Wednesday, February 23, 2011

An easy puzzle

Suppose I have some code like this:
(defun foo (x)
    (bar 42 x)))
Where wrapper-macro simply prints ‘Normal exit’ or ‘Throw’ as control returns from bar through foo. (If bar returns normally, all the return values are returned from foo after wrapper-macro prints. If bar exits via a throw, then the throw continues after wrapper-macro prints.)

The challenge: Implement wrapper-macro.

(If you wish, imagine that wrapper-macro simply expands to this:
(defun foo (x)
    (lambda ()
      (bar 42 x))))
and the challenge is to implement wrapper-function.)