Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!husc6!panda!genrad!decvax!cca!lmi-angel!rpk From: rpk@lmi-angel.UUCP (Bob Krajewski) Newsgroups: net.ai,net.lang.lisp Subject: Re: Common LISP style standards. Message-ID: <53@lmi-angel.UUCP> Date: Fri, 30-May-86 13:05:44 EDT Article-I.D.: lmi-ange.53 Posted: Fri May 30 13:05:44 1986 Date-Received: Wed, 4-Jun-86 00:07:12 EDT References: <2784@jhunix.UUCP> <3787@utah-cs.UUCP> Reply-To: rpk@lmi-angel.UUCP (Bob Krajewski) Distribution: net Organization: LISP Machine, Inc (Cambridge Engineering HQ) Lines: 47 Keywords: sequences, dynamic exit, compilation Xref: linus net.ai:3265 net.lang.lisp:765 In article <> michaelm@bcsaic.UUCP (michael maxwell) writes: >In article <3787@utah-cs.UUCP> shebs@utah-cs.UUCP (Stanley Shebs) writes: >>Sequence functions and mapping functions are generally preferable to >>handwritten loops, since the Lisp wizards will probably have spent >>a lot of time making them both efficient and correct (watch out though; >>quality varies from implementation to implementation). This is very true. It will be interesting to see how Lisp compiler technology meets the challenge... >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 )", 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... There are two Common Lispy ways doing this. The first is the use the function (SOME predicate sequence &rest more-sequences), which returns the first non-NIL result of the application of the predicate to the each set of elements of the sequences (like map). Since this is a generic sequence function that can take either vectors or lists, you'll probably want to write something like (some #'(lambda (x) (when (wonderful-p (sibling x)) (father x))) (the list a-list)) A good compiler would do two things here: it would first notice that the only sequence is a list. Thus, the ``stepping'' function for the sequence type (CDR, and CAR for element selection) is known in advance. And since that is so, it can open code the loop, thus generating a DO-like thing that you would have otherwise written by hand. Another way is to use CATCH and THROW. When the THROW is lexically visible from the CATCH, very good code can be generated in certain cases. As for whether it's icky or not, at least CATCH establishes a lexical scope for where the ``goto'' is valid, when the THROW is visible. -- Robert P. Krajewski Internet/MIT: RPK@MC.LCS.MIT.EDU UUCP: ...{cca,harvard,mit-eddie}!lmi-angel!rpk