Modify the handling of cond
Scheme allows an additional syntax for cond clauses, (<test> => <recipient>) . If <test> evaluates to a true value, then <recipient> is evaluated. Its value must be a procedure of one argument; this procedure is then invoked on the value of the <test> , and the result is returned as the value of the cond expression. For example
(cond ((assoc ’b ’((a 1) (b 2))) => cadr)
(else false))
returns 2 . Modify the handling of cond so that it supports this extended syntax.
I think the test code won't work as expected. For example, when running the first test case
The
condwill be evaluated before callingeval(applicative order). In other words, the above test case will actually beWhen calling
eval, the formal parameterexpwill be2, not a list expected