function call: expected a function after the open parenthesi

Discussion of Common Lisp
Post Reply
Requizm
Posts: 2
Joined: Tue Jan 02, 2018 2:50 am

function call: expected a function after the open parenthesi

Post by Requizm » Tue Jan 02, 2018 2:53 am

Code: Select all

(define (paint d r) (if (empty? d) null (if (empty? r) null (
                                             (list
                                         (first d) (first r))                       
                                         (paint (rest d) (rest r))
                                        )
                                        )))

(paint (list 1 2 3 4) (list 1 2 3))
I'm run this script and take that error:
function call: expected a function after the open parenthesis, but received (list 3 3)

sylwester
Posts: 133
Joined: Mon Jul 11, 2011 2:53 pm

Re: function call: expected a function after the open parent

Post by sylwester » Wed Jan 03, 2018 2:44 pm

Ive just made a SO Q&A that answers this question.
The part of the text that is most suitable for your case:

Trying to group expressions or create a block

Code: Select all

(if (< a b)
    ((proc1)
     (proc2))
    #f)
When the predicate/test is true Scheme assumes will try to evaluate both (proc1) and (proc2) then it will call the result of (proc1) because of the parentheses. To create a block in Scheme you use begin:

Code: Select all

(if (< a b)
    (begin 
      (proc1)
      (proc2))
    #f)
In this (proc1) is called just for effect and the result of teh form will be the result of the last expression (proc2).
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p

Requizm
Posts: 2
Joined: Tue Jan 02, 2018 2:50 am

Re: function call: expected a function after the open parent

Post by Requizm » Sat Jan 06, 2018 11:13 am

sylwester wrote:Ive just made a SO Q&A that answers this question.
The part of the text that is most suitable for your case:

Trying to group expressions or create a block

Code: Select all

(if (< a b)
    ((proc1)
     (proc2))
    #f)
When the predicate/test is true Scheme assumes will try to evaluate both (proc1) and (proc2) then it will call the result of (proc1) because of the parentheses. To create a block in Scheme you use begin:

Code: Select all

(if (< a b)
    (begin 
      (proc1)
      (proc2))
    #f)
In this (proc1) is called just for effect and the result of teh form will be the result of the last expression (proc2).
Thanks for help :D

Post Reply