[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: JONL at MIT-MC, SHRAGE at WHARTON-10
- From: MARC at MIT-XX
- Date: Tue ,11 Nov 80 14:15:00 EDT
- Cc: LISP-FORUM at MIT-MC, LISP-DISCUSSION at MIT-MC
MDL has had a similar construct for quite some time (five years?).
There are two SUBRs, MAPF (MAP-First) and MAPR (MAP-Rest), which map over
successive elements and successive RESTs (CDRs) of structures. The syntax
<MAPF ;"or MAPR"
struc1 ... strucN >
The way it works is that the loopf (usually an imbedded FUNCTION but also
permitted to be an externally defined function or a SUBR) is applied to
successive elements (or RESTs) of the strucs. This continues until one
of the strucs "runs out" (becomes empty), or the loopf performs a MAPLEAVE
or a MAPSTOP.
If the finalf is a FALSE (NIL in conventional Lisps), MAPF/R is
thus just a FOR-EACH style loop. If the finalf is applicable, it is
applied to the accumulated values of the applications of the loopf. The
loopf may control the accumulation of values itself by performing MAPRETs
inside itself. The arguments of MAPRET (any number) become the values from
that application of the loopf. MAPSTOP is like MAPRET except that it says,
after accumulating these arguments, apply the finalf and return.
MAPLEAVE says "return my argument as the value of the MAPF/R".
Note also that if no strucs are supplied, MAPF becomes a sort of
generator function to build structures.
<COND (<WIN? .X> <MAPRET .X>)
returns a list of the members of CANDIDATES that pass a certain test.
<COND (<==? <1 .X> .Y> <MAPLEAVE .X>)>>
is precisely <MEMQ .Y .X>.
returns a list of the elements in a hash-table. (! is the MDL construct
that means "take my elements instead of me")
MDL, of course, is coming soon to a machine near you...