I have this task where i'm working with a metacircular evaluator, and i define a new cond
like this:
(define cond 3)
As well as else
:
(define (else x) (/ x 2)
My question is why does this (below) actually work?
(cond ((= cond 2) 0)
(else (else 4)))
How does Scheme know which cond
is my defined cond and my else
, over the conditional cond
and else
?
(Feel free to edit the title, as i'm not sure how to formulate my question)
It depends on how you have implemented
cond
in the metacircular evaluator. Usually it checks some operators for symbols likequote
andcond
and then do someething special. Thuscond
in operator position will be expanded ascond
whilecond
in other circumstances would be evaluated as if it was a variable.