-1

This may be a very noob question but I am new to Scheme. When I try the following command:

(equal? (((lambda (s z) (s 3 z)) + 0) 3))

It gives me following error:

application: not a procedure;
 expected a procedure that can be applied to arguments
  given: 3
  arguments...:

The way I understand, the expression should evaluate to (+ 3 0) which is equal to 3. Where am I going wrong?

dc95
  • 1,319
  • 1
  • 22
  • 44

1 Answers1

4

One paranthesis pair too much.

I recommend you to use automatic indentation in DrRacket for each argument in such more complicated expressions.

This is the correct version:

(equal? ((lambda (s z) (s 3 z)) + 0)
        3)
;; #t

Note, the 3) is exactly aligned to the ((lambda ..., indicating it is at exactly the same level with the lambda-expression containing s-expression.

See what would have happened, if you would have started new line in DrRacket with the previous code, to specify and test that 3 is the second argument to equal?:

(equal? (((lambda (s z) (s 3 z)) + 0)
         3))

Do you see? The 3 is off by one position. It is not exactly aligned to the beginning of (((lambda .... But you would know, it should, if 3 and the lambda expression-bearing s-expression are at the same hierarchy level (like being arguments to the function equal?).

That is why lispers swear by automatic-indentation-capable lisp editors. Because through such small, but important, hints the automatic indentation helps you to tame the parantheses.

Gwang-Jin Kim
  • 9,303
  • 17
  • 30