Explanation of macros; Haskell macros
Coby Beck
cbeck at mercury.bc.ca
Fri Oct 31 00:20:43 EST 2003
"Pascal Costanza" <costanza at web.de> wrote in message
news:bnscfb$p1k$1 at newsreader2.netcologne.de...
>
> The essence of this is as follows:
>
> (defmacro my-cond (&body body)
> `(cond ,@(append body '(t (handle-the-default-case))))
>
Just to provide a more apparently general (and working ;) version, analogous
to CL's ECASE:
CL-USER 90 >
(defmacro econd (&body body)
`(cond ,@(append body
`((t (error (format nil
"fell through ECOND form. could not
satisfy any of the following: ~{~%~A~}~%"
(mapcar #'(lambda (cond)
(car cond))
',body))))))))
ECOND
CL-USER 91 > (econd
((= 3 4) "foo")
((= 4 4) "bar"))
"bar"
CL-USER 92 > (econd
((= 3 4) "foo")
((= 4 5) "bar"))
Error: fell through ECOND form. could not satisfy any of the following:
(= 3 4)
(= 4 5)
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other
options
--
Coby Beck
(remove #\Space "coby 101 @ big pond . com")
More information about the Python-list
mailing list