Subject: Re: Macros OR, AND From: Erik Naggum <email@example.com> Date: Sat, 17 Nov 2001 04:49:16 GMT Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * Thomas F. Burdick | I can see doing this for AND, but I think it's a bad idea, because it | makes no sense for OR. With AND, the value of the form is only ever | going to be the value(s) of the last form, or NIL. With OR, though, | it's weird. (or (cached-result mumble frotz) (cheap-algorithm-if-possible mumble frotz) (expensive-general-case mumble frotz)) I also tend to write (or (gethash mumble frotz) (setf (gethash mumble frotz) (whatever mumble))) mostly because I cannot agree with myself on what the name of a macro that does this should be called. The non-zero cost of computing the proper entry in the hash table should have been possible to optimize. Since the value to be stored could be expensive, too, it would be a pretty complex function interface: (gethash-but-sethash-if-unset <key> <hashtable> <function>) typically called with a function (or probably a closure) to call to obtain the value to store if the hash table had no entry for that key. It is too complicated and messy for whatever limited utility it has. Adding more stuff to the language, one could of course have a new macro to build functions that should be called in such functions: (gethash-but-sethash-if-unset <key> <hashtable> (delay <expression>)) where delay would be defined no more complicated than this: (defmacro delay (form) `(lambda () ,form)) but it would communicate the programmer's intent better than the lambda expression alone would do. However, this is somethiing that needs a bit more "community support" and wider application and implementation if it were to be useful. Languages that have such a delay form typically have a way to call the function the first time the value is asked for, storing ib back into the variable. And that is the exact feature sought here. For the time being, I think it looks better to write (or end (setq end (length <sequence>))) than a much more complicated mechanism. /// -- Norway is now run by a priest from the fundamentalist Christian People's Party, the fifth largest party representing one eighth of the electorate. -- Carrying a Swiss Army pocket knife in Oslo, Norway, is a criminal offense.