Tuesday, September 11, 2007

A useful macro

When you return a (multiple) value(s) from a Lisp function you use either use return-from or return macro. Now how about this, if you have a macro which will look like:

(defun foo()

(return “foo”))

This can be useful as we can do away with all the “block” statements. The macro that I use for this purpose is fairly simple:

(defmacro xreturn(x)

(block nil (return x)))

I know that it has one limitation that it does not return multiple values but that's fairly easy for any lisper to figure out right. ;-)

Please do not ask me about the naming convention I followed. Any feedback in this will be more than welcomed.

No comments: