[mod.ai] Common Lisp style

Fahlman@C.CS.CMU.EDU.UUCP (05/31/86)

    A common situation we find ourselves in is the following.  We have a
    long list, and we wish to apply some test to each member of the list.
    However, at some point in the list, if the test returns a certain value,
    there is no need to look further: we can jump out of processing the list
    right there, and thus save time.  Now you can jump out of a do loop with
    "(return <value>)", but you can't jump out of a mapc (mapcar etc.) with
    "return."  So we wind up using "do" a lot of places where it would
    otherwise be natural to use "mapcar".  I suppose I could use "catch" and
    "throw", but that looks so much like "goto" that I feel sinful if I use
    that solution...

    Any style suggestions?

Well, if you were using "Monster, I mean Common, Lisp..." there would be
a built-in function to handle this case.  If I understand correctly what
you are asking for, the function is FIND-IF.  Our attempt to meet
various needs like this is why the language is big.  You can't have it
both ways.

In a Lisp without a built-in solution, the right answer is probably to
create your own FIND-IF macro and use it for this case.  It creates the
same DO-loop you would have to write, but is much less confusing for the
casual reader and less prone to errors once you get the macro right.

If you find yourself wrestling with a variety of such problems, there
are several iteration packages available that provide a somewhat
perspicuous syntax for the user and that create efficient DO loops of
various kinds.  Your Franz Lisp vendor can probably point you to a
version of the LOOP facility that will run on your system.  Something of
this sort will probably find its way into standard Common Lisp
eventually, but we are having a hard time deciding on a syntax that we
all can live with.

-- Scott