Can someone please explain me why :
(define a (lambda() (cons a #f)))
(car (a)) ==> procedure
((car (a))) ==> (procedure . #f)
I don't think I get it. Thanks
Can someone please explain me why :
(define a (lambda() (cons a #f)))
(car (a)) ==> procedure
((car (a))) ==> (procedure . #f)
I don't think I get it. Thanks
This
(define a (lambda() (cons a #f)))
defines a procedure, a
, which when called will return the pair
(<the procedure a> . #f)
i.e. whose car
is the procedure itself, and whose cdr
is #f
.
In other words, the result of evaluating
(a)
is the result of calling the procedure a
with no arguments, which is, by definition of a
above,
(<the procedure a> . #f)
Hence,
(car (a))
is <the procedure a>
(because it means "call car
with the result of evaluating (a)
")
When you add another pair of parentheses
((car (a)))
you're calling that procedure, which - since it's the procedure a
- returns the same result as (a)
,
(<the procedure a> . #f)
define
from top level defines a global variable a
.
The anonymous procedure (lambda() (cons a #f)
, when called, makes a pair out of the evaluation of a
and #f
.
When you evaluate a
you get a procedure. In my system you get #<procedure:a>
.
When you evaluate (a)
you get (#<procedure:a> . #f)
. Now the way procedures display is highly implementation dependent. There are no standard, but many will use a convension where the name a
would be present, but don't count on it.
Since a
also can be accessed as the car
of the result of calling a
you can ((car (a)))
and get the same as (a)
. That's because (eq? a (car (a)))
is #t
.