I'm super new to this language and I came across a problem. Hope someone can help me out. Thanks.
Basically, I want to define a higher-order function make-adder. Here is my code.
(define (make-adder num)
(define (foo x)
(+ x num)))
(define adder (make-adder 5))
(adder 8) ;error points to here
But, I wonder why I got this error message.
# Error: expected
# 4
# but got
# Traceback (most recent call last):
# ...
# SchemeError: str is not callable: foo
another interpreter I use also gave me an error but in a different way
Traceback (most recent call last)
0 (adder 8) [frame = Global]
Unable to pass parameters into the Symbol 'foo'
First, I wanted to know why I cannot use this code to define the make-adder higher order function like I always did in Python.
Second, I suppose that what a define procedure expression returns is a string ? (because it said str foo is not callable) But when I tried to test it out
scm> (define (foo x) (+ 1 x))
foo
scm> (string? (define (foo x) (+ 1 x)))
#f
So it turns out that it's not a string. I am so confused. What does foo stand for here? Is it a string or something else? Why I cannot call from it?
Hope anyone can help me out. Thank you.
definein other places than the report specifies so while usingdefineas an expression might work in your implementation it is guaranteed to fail under R5RS in Racket. In other implementation it might silently fail since R5RS doesn't dictate how a non Scheme program should be handled. - Sylwester