Subject: Re: newbie: non local exits in CL
From: Erik Naggum <>
Date: 1997/07/15
Newsgroups: comp.lang.lisp
Message-ID: <>

* Laurent Peron
| I was thinking of CL idioms, readability, and maintainability.  I have
| not read much good CL code yet, and I am not sure of what is the
| idiomatic way of expressing what I want to express.

to become certain and to choose the right form by reflex will take a _very_
long time.  however, idioms are not quite as necessary in Common Lisp as
they are in, e.g., C++ and Perl.  well, I guess it depends on what you call
"idioms".  is a functional programming style an "idiomatic" issue?

to take an example I have been idly wondering about.  suppose you have an
Internet address as an integer.  you want to produce a dotted-decimal form
of it.  suppose we have the following code:

(defvar *network-byte-order*
    (list (byte 8 0) (byte 8 8) (byte 8 16) (byte 8 24))
  "Bytes of an address in network byte order.")

(defun dotted-decimal (address)
  "Return the dotted-decimal form of the IP address ADDRESS."
  (format nil "~{~D~^.~}"
    (mapcar #'ldb *network-byte-order*
	    (list address address address address))))

now, is the `mapcar' form better written like this?

    (mapcar (lambda (byte) (ldb byte address)) *network-byte-order*)

is a repeating list of the same elements better done with a function
`repeatedly', as in (defun repeatedly (&rest x) (nconc x x)):

    (mapcar #'ldb *network-byte-order* (repeatedly address))

or is it better to use the straight-forward case:

(defun dotted-decimal (address)
  "Return the dotted-decimal form of the IP address ADDRESS."
  (format nil "~D.~D.~D.~D"
    (ldb (byte 8 0) address)
    (ldb (byte 8 8) address)
    (ldb (byte 8 16) address)
    (ldb (byte 8 24) address)))

I don't think such question have definite answers, but I'm not sure I'd
rate this is as _idiomatic_ usage of CL.  actually, the languages where I
have heard "idiom" touted the most are Perl and C++, which sort of makes me
wonder about the value of "idiom" mainly as a cover over bad language
design, although I know this is unfair to good idioms.  I'd suggest you
just write working code and keep an open mind to new suggestions when you
read code from others.  above all, don't worry about it.

(incidentally, I think the Year 2000 problem is one of idiom and pattern
and failure to use the proper abstraction in dealing with input and output
of machine representations of dates.  computers never should have had to
count the number of digits in a year representation.  in my book, too much
idiom and pattern is much worse than abstraction when people are blindly
copying code.)

see Richard P. Gabriel: Patterns of Software for an excellent treatment of
the pros and cons of abstraction.  I found it very refreshing and clear.

if DUI is "Driving Under the Influence"
then GUI must be "Graphics Under the Influence"