From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news2.kpn.net!news.kpn.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Macros OR, AND References: <3BF4D9A4.D07BF449@eurocom.od.ua> <87r8qy5lr0.fsf@noetbook.telent.net> Mail-Copies-To: never From: Erik Naggum Message-ID: <3214961354417483@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 56 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 17 Nov 2001 04:49:16 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader3.kpnqwest.net 1005972556 193.71.66.49 (Sat, 17 Nov 2001 05:49:16 MET) NNTP-Posting-Date: Sat, 17 Nov 2001 05:49:16 MET Xref: archiver1.google.com comp.lang.lisp:20188 * 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 ) 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 (delay )) 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 ))) 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.