(define inc (lambda(x)(( x 1 ))))
I created the line of code above as an answer to the question
"Create a function called "inc" which will be given a numeric argument, and returns a number larger by one. For instance,
(inc 6) => 7
"
CodePudding user response:
You have an extra set of parentheses. You want
(define inc (lambda(x)( x 1 )))
instead of
(define inc (lambda(x)(( x 1 ))))
CodePudding user response:
Probably the most common Scheme & Lisp problem is having too many parentheses.
The correct syntax is (lambda (parameters) expression)
, not (lambda (parameters) (expression))
.
(That is, you should not wrap the function body in parentheses.)
In your case, you have
(inc 6)
which is
((lambda(x)(( x 1 ))) 6)
which is
(( 6 1))
which is
(7)
which is not the same as 7
, but an attempt to call 7
as a parameterless procedure.
You should write
(define inc (lambda (x) ( x 1)))
or
(define (inc x) ( x 1))