Cerys%TILDE%ti-csl.CSNET@CSNET-RELAY.ARPA.UUCP (06/02/86)
Date: 15 May 86 17:42:18 GMT From: tektronix!uw-beaver!ssc-vax!bcsaic!michaelm@ucbvax.berkeley.edu (michael maxwell) 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? It sounds like the function you want is MEMBER-IF. This takes two required arguments, a predicate and a list. As soon as the predicate succeeds on one of the elements of the list, the tail of the list is returned, else NIL is returned. There is nothing wrong with using DO or any of the mapping functions, as long as you are using the "best" function for the task. In the case you've described, MEMBER-IF is perfect because it immediately conveys to the reader (which may be yourself months after you've written it) what is being tested for. DOs and RETURNs can hide this meaning. Another useful variant of DO is DOLIST, which is similar (and prefered by many) to MAPC. Within our group, we prefer to use the mapping functions only where they appear to be "natural" to the task (eg, list transformations). But granted, what is "best" and "natural" depends a lot on your background and approach to Lisp.
jay@ROCHESTER.ARPA.UUCP (06/12/86)
I admit that there is a significant overlap between the people
interested in Artificial Intelligence and those interested in the
LISP programming language, but it should be obvious that articles
like "Common LISP style standards" and "LISP for IBM PCs" should
be posted to newgroups other than mod.ai, and such newsgroups do
exist. This newsgroup has a large amount of traffic, and I expect
that many readers have unsubscribed due to the large amount of
inappropriate submissions.
I would mail this message to individuals who do not realize this,
but there have been so many it would not be effective. Mostly
this message is to the moderators, who should be enforcing the
focus of the newsgroup.
Jay Weber
Department of Computer Science
University of Rochester
jay@rochester.arpa
[Unfortunately there are few relevant discussion lists on
the Arpanet side of the gateway. We do have one on workstations
and others on particular micros or Lisps, but nothing of the
required generality. I will be glad to help anyone who wants
to start a list devoted to Lisp or any other topic currently
covered by AIList:
Expert Systems AI Techniques
Knowledge Representation Knowledge Acquisition
Problem Solving Hierarchical Inference
Machine Learning Pattern Recognition
Analogical Reasoning Data Analysis
Cognitive Psychology Human Perception
Natural Language Computational Linguistics
AI Languages and Systems Machine Translation
Theorem Proving Decision Theory
Logic Programming Computer Science
Automatic Programming Information Science
AI & Society Sociology of AI
AI & Business AI Workstations
(Step forward, folks, or I may burn out soon. Besides, its lots
of fun and it puts you in contact with the best people.) -- KIL]