I’m new to programming, working my way through SICP, and loving it. Though I’m a bit confused about scheme’s define syntax, mainly, what’s the difference between:
(define foo bar)
and:
(define (foo) bar)
Is the first one just assigns bar to foo and execute it? While the second assigns and waits for the call?
if so how would you go about calling the function inside another function, say within an if statement,
(if (foo) ...)
or
(if foo ...)
The first version creates a variable named foo and assigns it a reference to bar. Nothing else gets executed.
The second version creates a function with the body bar. The function doesn’t get executed, it gets filed away (guessing that’s what you mean by ‘waiting’?).
You always call a function by making it the first item in a list and evaluating the list.
create a variable
create another variable referencing the other variable
create a function that returns whatever is in a
evaluate the function
write a function that evaluates another function and returns the result
now change it to return the function c