Subject: Re: Creating setf expanders on methods
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 01 Mar 2009 07:38:06 -0600
Newsgroups: comp.lang.lisp
Message-ID: <bPydneGPeqgjEjfUnZ2dnUVZ_jOWnZ2d@speakeasy.net>
Marco Antoniotti <marcoxa@gmail.com> wrote:
+---------------
| TJ Atkins <JackalM...@gmail.com> wrote:
| > rpw3@rpw3.org (Rob Warnock) wrote:
| > > Just curious... How did you "handle it"?
| > > Like Marco, I consider the default argument to GETHASH incredibly useful,
| > > especially when counting things, e.g., (incf (gethash key ht 0)).
| >
| > ref went back to having a (place &rest indexes) argument signature, so
| > in the case of a hash table, (first indexes) is the key and (second
| > indexes) is the default value (matching gethash's argument signature,
| > except with the place in front like it should be). �Conveniently,
| > (second indexes) returns nil on a 1-element list, which is precisely
| > the standard default value for hashes.
| 
| Yep.  That'd work.  I would also change the signature to
| 
| (defgeneric ref (container index/key &rest more-indexes-or-defaults))
| ;; We LOVE long indentifiers :)
| 
| After all you always have at least one index/key.  I think this is
| better from the programmer point of view...
+---------------

Heh. Looking for a place to file this, I stumbled across a 2002 thread
about the very same topic [a REF macro and/or special form], in which
you had this to say [slightly reformatted for brevity]:

    Newsgroups: comp.lang.lisp
    Date: 23 Jan 2002 10:19:58 -0500
    Subject: REF as a special operator (Re: Ciel (was: Re: The true faith))
    From: Marco Antoniotti <marcoxa@cs.nyu.edu>
    Message-ID: <y6chepd857l.fsf_-_@octagon.mrl.nyu.edu>
    ...
    (defmacro ref (item (&rest indexes-or-keys)
			&key default
			&allow-other-keys) ...)

    So that for an 1D array A1: (ref a1 3) == (aref a1 3)
    for a 2D array A2:          (ref a2 (3 4)) == (aref a2 3 4)
    for an hash-table HT:       (ref ht 'key) == (gethash 'key ht)
    again:                      (ref ht 'key :default 4) == (gethash 'key ht 4)
    ...[some discussion of VALUES]...
    for an instance I of class C, [with
    slot (s :accessor s-of)]:   (ref I 's) == (slot-value I 's)
    but then for a hairy data structure HDT
    indexed by strings....      (ref hdt ("string1" "s2" "s3") :default 123)

To which Thomas Burdick added:

    I just posted something similar, and made a dismissive comment about
    it, but I think I like this take on it.  There's one dereferencing
    position, and it can be either a subscript or a list of subscripts.
    I think I'd want the position to be evaluated [so your second example
    would be (ref a2 '(3 4)) ].
    ...

    > (ref I 's) == (slot-value I 's

    I actually don't like this as a default behavior.  As a report from
    the field, I've already caught one bug because an error was raised by
    trying to REF an object that wasn't REF'able.  If all classes were
    REF'able by default, this would have bitten me later.  It's pretty
    easy to make a ref-mixin class. ...

Does this blast from the past inform/change your current suggestion(s)?


-Rob

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