Path: utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!decvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!its63b!aiva!jeff From: jeff@aiva.ed.ac.uk (Jeff Dalton) Newsgroups: comp.lang.lisp Subject: Re: CL question - conditional list elements Message-ID: <244@aiva.ed.ac.uk> Date: 29 Jan 88 18:05:31 GMT References: <1350005@otter.HP.COM> <2002@russell.STANFORD.EDU> <591@cresswell.quintus.UUCP> Reply-To: jeff@uk.ac.ed.aiva (Jeff Dalton) Organization: Dept. of AI, Univ. of Edinburgh, UK Lines: 48 In article <591@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >The giveaway was the Pop version. > [% a, b, if t1 then c endif, d if t2 then e endif, f, g %] >operates like this: > push a magic marker on the stack > push a > push b > if t1 then push c endif > push d > if t2 then push e endif > push f > push g > make a list of everything from the top of the stack > down to the magic marker. Oh, so it's pushing on the stack we want. That can be done: 1> (defmacro include-if (test values) `(if ,test ,values (values))) INCLUDE-IF 2> (multiple-value-call #'list 1 2 3 4 5 (include-if t (values 6 7)) 8 9 10 (include-if nil (values 11 12)) 13 14 15) (1 2 3 4 5 6 7 8 9 10 13 14 15) Is that enough? I can write the elements not a list thereof. It's guaranteed to build a new list. It doesn't officially generate any garbage. (Does someone complain that it's not GUARANTEED not to produce garbage? Such guarantees are easy for PopLog because there's only one implementation.) >The general answer to questions of the form "here's something I can >do in Pop, how do I do it in CL" is "you learn how to write Lisp and >then you won't find yourself wanting it." Of course the same is true >in the other direction. The other general answer seems to be "write >a macro..." Some people, I think, will always want some things even after they learn how to write Lisp. After all, Lisp can't be all things to all people. Jeff Dalton, JANET: J.Dalton@uk.ac.ed AI Applications Institute, ARPA: J.Dalton%uk.ac.ed@nss.cs.ucl.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!J.Dalton