Explanation of macros; Haskell macros
Coby Beck
cbeck at mercury.bc.ca
Sat Nov 1 22:14:11 EST 2003
"Olaf Klischat" <olaf.klischat at isst.fhg.de> wrote in message
news:874qxpgp70.fsf at swangoose.isst.fhg.de...
> "Coby Beck" <cbeck at mercury.bc.ca> writes:
>
> > "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))))))))
>
>
> Just for the record: Is the "append" stuff necessary? Why not write
> this as
>
> (defmacro econd (&body body)
> `(cond , at body
> (t (error (format nil "fell through ECOND form. could not satisfy any of
the following: ~{~%~A~}~%"
> ',(mapcar #'(lambda (cond)
> (car cond))
> body))))))
>
That works. I blame Pascal for my gratuitous use of append and now I have
been exposed as one of those copy-paste-alter code monkeys without a formal
correctness proof in my head ;)
--
Coby Beck
(remove #\Space "coby 101 @ big pond . com")
More information about the Python-list
mailing list