[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(REDUCE #'OVERHEAD (MAP ...))
> From: James Larus <firstname.lastname@example.org>
> I use REDUCE quite frequently and recently ran across a strange
> interaction between it and another CL feature. I was trying to
> (reduce #'or (mapcar ...))
If you're doing a lot of stuff like this, maybe you should look into
the "Generic Mapping Functions" that Daniel Corkill has defined.
They do much of what REDUCE + MAP is used for, but
the notion of combining the results of mapping is generalized,
and is done more efficiently since it isn't always necessary to cons
up the intermediate results.
MAPCAR can be thought of as using CONS to combine mapping results.
The above use of OR is generally done through SOME in Common Lisp, but
is expressed using the Generalized Maps as MAPC-OR. EVERY is MAPC-AND, and
MAPCAN (MAPC-NCONC) functionality is done better as MAPC-CONDCONS.
MAPC-MAX is a popular one, as is MAPC-+ (MAPC-UNION, MAPC-AVERAGE, etc).
There are also MAPL-xxx functions that operate on sucessive sublists.
We have plans to extend these to work on sequences and not just lists,
but haven't done it yet (:- of course, they handle circular-lists :-)
The MAP-FUN general form takes a gob of keywords
to allow just about any mapping combination to be defined, and all the
others are defined in terms of it. They are Functions, but have
Compiler transforms that convert them into very efficient DO loops.
We can probably get the code to anyone interested.
- Kelly Murray
University of Massachusetts