Subject: Re: Porting Ruby snippet to Lisp
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 21 Mar 2007 01:19:53 -0500
Newsgroups: comp.lang.lisp
Message-ID: <Lsidnf1J4LgUU53bnZ2dnUVZ_vamnZ2d@speakeasy.net>
Juho Snellman  <jsnell@iki.fi> wrote:
+---------------
| Brian Adkins <lojicdotcomNOSPAM@gmail.com> wrote:
| > Why do you feel "the generality of the setf form" is being "thrown 
| > away"? The task at hand is a specific one - to associate a key and
| > value in a hash. What do you feel the benefits of the following:
| >   (setf (gethash :key hash) value)
| > are compared to:
| >   (seth :key hash value)
| > given the task?
| 
| It doesn't extend to:
|   (incf (gethash :key hash) value)
|   (push (gethash :key hash) value)
|   (rotatef (gethash :key hash)
|            (gethash :other-key hash))
|   (setf (values (gethash :key hash)
|                 (gethash :key other-hash))
| 	(something-returning-two-values))
+---------------

In particular, it doesn't extend to one of my *favorite* idioms:

    (incf (gethash :key hash 0))

where the hash table doesn't need to have been preloaded in advance
with zeros for all possible keys! [Yes, (INCF (GETHASH :KEY HASH 0) VALUE)
also works, but I haven't found myself using it as often as the
unitary version.]


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607