[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: loop macro
Date: 4 Feb 86 15:50 PST
I think I prefer "lispy" iteration macros. Here is an example of what I
mean by a lispy iteration macro:
;; Return a list of the items in list-of-items
;; which pass the test TEST.
(iterate ((item in list-of-items))
(when (test item)
I would like to note that the implementation of such an iteration macro
is one of the reasons that FLET and LABELS were included. The expansion
of (ITERATE ((ITEM IN LIST-OF-ITEMS)) body) might look like
(DO ((#:G0001 LIST-OF-ITEMS (CDR #:G0001))
((NULL #:G0001) #:G0002)
(FLET ((COLLECT (X) (SETQ #:G0002 (NCONC #:G0002 (LIST X)))))
(DECLARE (INLINE COLLECT))
Of course, the FLET would need to define all kinds of collectors that might
be needed, including MAXIMIZE, SUM, and so on; this leaves a problem as to
what the initial value for the result should be, in case the collector is
never called. One can do better by groveling through the body, of course.
Yuk. Anyway, MACROLET is useful if some collector needs special syntax.