[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] Lisp programming style advice

From: Paul F. Dietz
Subject: Re: [Gcl-devel] Lisp programming style advice
Date: Sat, 26 Oct 2002 12:53:35 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826

Camm Maguire wrote:
Greetings!  In the course of addressing some of the ansi issues
revealed by Paul's tests, I'm finding myself writing ever more
sophisticated (for me) lisp code for GCL with a still partial
understanding of the language. I'd like to take a moment to solicit
the opinions of the list on the with-package-iterator macro I
committed recently.

(1) Don't write (if <form1> <form2>); write (when <form1> <form2>).
  This is easier to understand when <form2> is very large.
  Similarly, prefer (unless <form1> <form2>) to (if (not <form1>) <form2>).
  The reader should not be forced to scan down the page to search
  for the optional 'else' clause.

(2) Instead of

   (setq ,q (cdr ,q))
   (if (null ,q)
     ... ))


(if (null (setq ,q (cdr ,q)))

This reduces the indentation overload.

(3) You probably don't want a big body in a macrolet -- that can lead
  to lots of code expansion.  Instead, use a flet.

(4) Instead of (setq ,i (1+ ,i)), use (incf ,i).

And a bug:

(5) You are assigning a list to ,x at one point, but you declared ,x
  to be a fixnum.  Use multiple-value-setq instead.

(setq ,x (multiple-value-list
          (si::package-size (car ,q))))
(setq ,y (first ,x))
(setq ,x (second ,x))
(multiple-value-setq (,y ,x) (si::package-size (car ,q)))

(You don't want multiple-value-list to be consing up that short
temporary list anyway.)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]