Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!caip!lll-crg!seismo!mcvax!enea!kuling!martin From: martin@kuling.UUCP (Erik Martin) Newsgroups: net.ai,net.lang.lisp Subject: Re: Common LISP style standards. Message-ID: <945@kuling.UUCP> Date: Sat, 17-May-86 20:52:32 EDT Article-I.D.: kuling.945 Posted: Sat May 17 20:52:32 1986 Date-Received: Sat, 24-May-86 00:07:45 EDT References: <2784@jhunix.UUCP> Reply-To: martin@kuling.UUCP (Per-Erik Martin) Distribution: net Organization: The Royal Inst. of Techn., Stockholm Lines: 63 Xref: linus net.ai:3240 net.lang.lisp:745 In article <2784@jhunix.UUCP> ins_amrh@jhunix.UUCP writes: > > - How do you keep track of the side effects of destructive functions > such as sort, nconc, replaca, mapcan, delete-if, etc? Don't use them. I use destruction only when I need circular objects or when I need to speed up a program. In the latter case I write it strictly functional first and then substitute 'remove' with 'delete' and so on. This should not affect the semantics of the program if it is 'correctly' written from the beginning. But it's really a task for the compiler so You shouldn't need to think about it. > - When should you use macros vs. functions? I only use macros when i need a new syntax or a 'unusuall' evaluation of the arguments. (like FEXPR in Franz and MacLisp.) > - How do you reference global variables? Usually you enclose it > in "*"s, but how do you differentiate between your own vars and > Common LISP vars such as *standard-input*, *print-level*, etc? Allways "*"s. No differentiation. > - Documentation ideas? An 'owerview' description in the file header, more detailed on top of each function. Very few comments inline, use long function and variable names instead. Documentation strings in global variables and top level (user) functions. > - When to use DOLIST vs MAPCAR? Quite obvious. Use DOLIST when you want to scan through a list, i.e. just look at it. At the end of the list it returns NIL or the optional return form. You can also return something with en explicit RETURN. Use MAPCAR when you want to build a *new* list with a function applied to each element. > - DO vs LOOP? Write what you mean. If you mean 'repeat until dooms day' (whithout any variables bound) then use LOOP. > - Indentation/format ideas? Or do you always write it like the > pretty-printer would print it? A lot of white space in the code. The rest is very personal and hard to set up rules for. Nice editors usually have good ideas about how it should look like. > - NULL vs ENDP, FIRST vs CAR, etc. Some would say "FIRST" is > more mnemonic, but does that mean you need to use > (first (rest (first X))) instead of (cadar X) ?? Again, write what you mean. If you mean 'is this the end of the list we are just working with?' then use ENDP, if you mean 'is this NIL (an empty list)?', use NULL, and if you mean 'is this false?' use NOT. Write FIRST if you mean the first element of a list, SECOND for the second, THIRD for the third...and compinations of these when appropriate. At some limit this gets very messy though, and C*R is better. But in that case you perhaps should write your own accessor functions. When working with cons'es I always use CAR and CDR. My general rule is : Write what you mean and leave the task of efficiency to the implementation and compiler. Per-Erik Martin -- Per-Erik Martin, Uppsala University, Sweden UUCP: martin@kuling.UUCP (...!{seismo,mcvax}!enea!kuling!martin)