Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!nrl-cmf!ames!pasteur!ucbvax!hplabs!otter!kers From: kers@otter.HP.COM (Christopher Dollin) Newsgroups: comp.lang.lisp Subject: CL question - conditional list elements Message-ID: <1350005@otter.HP.COM> Date: 13 Jan 88 16:11:28 GMT Organization: Hewlett-Packard Laboratories,Bristol,UK. Lines: 36 Another question about idimatic and efficient code in CL. Suppose I wish to constrauct a list with conditional components, that is, components that may or may not be absent. [The actual application I had with this in was constructing a list of menu items, where some items were only appropriate in certain circumstances]. The nearest I seem to be able to get is (append ... list of some boring bits ... (if Condition1 Bit1 '()) ... list of more boring bits ... (if Condition2 Bit2 '()) .... list of yet more boring bits ... ) or some splicing version likely to compile to similar code. This doesnt seem too efficient (or nice to write, either!), even using -nconc- rather than -append- - any comments, suggestions, or whatever? Regards, Kers | "Why Lisp if you can talk Poperly?" --------------------------------------------------------------------------- I thought you'd never ask. [% ... boring bits ... [note: the elements, not a list thereof] if Condition1 then Bit1 endif; ... more boring bits ... if Condition2 then Bit2 endif; ... final boring bits ... %] No garbage.