Page 1 of 1

function call: expected a function after the open parenthesi

Posted: Tue Jan 02, 2018 2:53 am
by Requizm

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)

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

Posted: Wed Jan 03, 2018 2:44 pm
by sylwester
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).

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

Posted: Sat Jan 06, 2018 11:13 am
by Requizm
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