Subject: Re: Porting Ruby snippet to Lisp
From: (Rob Warnock)
Date: Wed, 21 Mar 2007 01:19:53 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Juho Snellman  <> wrote:
| Brian Adkins <> 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 Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607