This is from the SICP course for the environmental model section:
(define make-counter
(lambda (n)
(lambda () (set! n (+ n 1))
n)))
Below,the interpreter says that (make-counter 0)
is a procedure:
> (make-counter 0)
#<procedure:...make_counter.rkt:8:5>
Below, I define c1
to be (make-counter 0)
.
(define c1 (make-counter 0)
Below is where I get confused as to the reason (c1)
returns the counter values instead of "procedure"
.
>(c1)
1
> (c1)
2
> (c1)
3
My thinking process is that if (c1)
points to a procedure, (make-counter)
, then (c1)
should return "procedure:...make_counter.rkt:8:5"
.
Because procedure -> procedure.
I see what should happen, I am just confused, conceptually, as to how and why.