Re: anamorphic macros
- From: "Steven M. Haflich" <smh@xxxxxxxxxxxx>
- Date: Sat, 07 May 2005 05:18:17 GMT
Tron3k wrote:
Hi, I'm wondering why Loop is unfit for use in macros. If so, I might have some troubles. =)
I think Frode may be prejusiced against loop. Acceptance of loop is something of a religious issue among Lisp programmers. It is counterproductive to argue about it, but I'll go just this far: It is certainly possible that a buggy loop implementation could expand into code that has pathological anamorphicisms, but I see no way in which these problems would be fundamental to the semantics of loop. Rather, they would be considered bugs.
The closest thing I've seen to a common anamorphicism problem in loop is that loop expands into a block that by default is names nil. Nil is a symbol exported from the cl package, and therefore use of loop inside the expansion of some iteration macro may promiscuously block [sic -- a pun!] some inner return-from. A quick example (untested):
(defmacro dolist-by-cddr ((var list &optional retform) &body body)
(let ((x (gensym))
`(loop for x on ,list by #'cddr
as ,var = (car ,x)
do ,@body
finally (return ,retform))))Now, if someone used this macro this way
(dolist (x my-caches)
(dolist-by-cdr (y x)
...
(when mumbl (return nil))
...))the return-from would incorrectly return from the nil-named block in the loop inserted by dolist-by-cddr.
The fix for this is either to document clearly that dolist-by-cddr inserts a nil-named block (lisk the other standard do-mumbl macros) or else to add a named ,(gensym) clause to the dolist-by-cddr expansion. More oftent than not programmers forget to do one or the other. When they do, and when a user programmer happens to use a return in the body, it can be a difficult bug to diagnose. .
- Follow-Ups:
- Re: anamorphic macros
- From: Frode Vatvedt Fjeld
- Re: anamorphic macros
- From: Kalle Olavi Niemitalo
- Re: anamorphic macros
- References:
- anamorphic macros
- From: Knut Olav Bøhmer
- Re: anamorphic macros
- From: Pascal Costanza
- Re: anamorphic macros
- From: Frode Vatvedt Fjeld
- Re: anamorphic macros
- From: Tron3k
- anamorphic macros
- Prev by Date: Re: This Lispofobics really gone too far
- Next by Date: Re: Comparing Lisp conditions to Java Exceptions
- Previous by thread: Re: anamorphic macros
- Next by thread: Re: anamorphic macros
- Index(es):
Relevant Pages
|