Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!ames!henry.jpl.nasa.gov!elroy.jpl.nasa.gov!aero!abbott From: abbott@aerospace.aero.org (Russell J. Abbott) Newsgroups: comp.lang.smalltalk Subject: A smalltalk "list" operation Message-ID: <57474@aerospace.AERO.ORG> Date: 8 Sep 89 16:39:38 GMT Reply-To: abbott@itro3.aero.org (Russell J. Abbott) Organization: The Aerospace Corporation, El Segundo, CA Lines: 45 If anyone is interested I've discovered a cute way to implement a "list" operation in smalltalk. If this is old hat, excuse my mentioning it. In Lisp, one can write, for example, > (list (plus 1 2) 4) and get (3 4) That is, "list" takes an arbitrary number of arguments and returns a list containing the evaluations of those arguments. In smalltalk there appears to be no equiivalent. One could write something like: #( (1 + 2) 4) but one would get an array containing two elements, the first of which is an array containing the three elements: 1, +, and 2. That is, there is no evaluation. The way around this is to define: (1) an instance creation method (which I call "<") that inserts its argument into the newly created object and (2) an "add:" method (which I call ",") for Collection. Then one can write: Set < (1 + 2), 4 This will yield: Set(3 4). The "<" operator should be read similarly to its use in the Unix shell as "redirect," i.e., create a set and put these elements into it. Of course, this structure may be nested: Set < 1, (Set < (2+3), 4), 5 which yields: Set(1, Set(5, 4), 5) While doing this, I found myself wishing that smalltalk had a parser similar to prolog's in which one could define and redefine operators and their precedences. The smalltalk syntax is so simple, such a parser should not be too much to ask. -- -- Russ abbott@itro3.aero.org