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
On
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.
This
defines a procedure,
a, which when called will return the pairi.e. whose
caris the procedure itself, and whosecdris#f.In other words, the result of evaluating
is the result of calling the procedure
awith no arguments, which is, by definition ofaabove,Hence,
is
<the procedure a>(because it means "callcarwith the result of evaluating(a)")When you add another pair of parentheses
you're calling that procedure, which - since it's the procedure
a- returns the same result as(a),