From: Tamas K Papp
Subject: how would you name this macro?
Date: 
Message-ID: <6iibqrFqoqt7U1@mid.individual.net>
I frequently find that I need to access a slot of a slot of a slot, etc.  
Hence

(defmacro slot-path (instance &rest path)
  "Follow the path of slots starting from instance recursively.  
setf'able."
  (unless path
    (error "empty slot path"))
  (labels ((rec-expand (path)
	     (if path
		 (list 'slot-value
		       (rec-expand (cdr path))
		       (car path))
		 instance)))
    (rec-expand (reverse path))))

Example:

(defclass c-a ()
  ((a :initarg :a)))

(defclass c-b ()
  ((b :initarg :b)))

(defparameter *c* (make-instance 'c-a :a (make-instance 'c-b :b 2)))
(slot-path *c* 'a 'b)      ; => 2
(setf (slot-path *c* 'a 'b) 4)
(slot-path *c* 'a 'b)      ; => 4

But the name seems a bit weird.  Any suggestions?  Perhaps this already 
exists somewhere else :-)

Tamas

From: namekuseijin
Subject: Re: how would you name this macro?
Date: 
Message-ID: <7ad854b4-f2cc-427c-af97-6286463716e5@w7g2000hsa.googlegroups.com>
Sounds quite slotty to me. :)
From: Marco Antoniotti
Subject: Re: how would you name this macro?
Date: 
Message-ID: <687ba70f-ebf3-4c20-ba17-96985ccd0802@x41g2000hsb.googlegroups.com>
On Sep 7, 5:55 pm, Tamas K Papp <······@gmail.com> wrote:
> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
>
> (defmacro slot-path (instance &rest path)
>   "Follow the path of slots starting from instance recursively.  
> setf'able."
>   (unless path
>     (error "empty slot path"))
>   (labels ((rec-expand (path)
>              (if path
>                  (list 'slot-value
>                        (rec-expand (cdr path))
>                        (car path))
>                  instance)))
>     (rec-expand (reverse path))))
>
> Example:
>
> (defclass c-a ()
>   ((a :initarg :a)))
>
> (defclass c-b ()
>   ((b :initarg :b)))
>
> (defparameter *c* (make-instance 'c-a :a (make-instance 'c-b :b 2)))
> (slot-path *c* 'a 'b)      ; => 2
> (setf (slot-path *c* 'a 'b) 4)
> (slot-path *c* 'a 'b)      ; => 4
>
> But the name seems a bit weird.  Any suggestions?  Perhaps this already
> exists somewhere else :-)
>
> Tamas

If you use readers, this is just COMPOSE.

    (funcall (compose 'reader1 'reader2 ... readerN) object)

Apart from that, I would go for a non English noun.  Something like

    (defmacro <<< (...) ...)

Cheers
--
Marco
From: Andy Chambers
Subject: Re: how would you name this macro?
Date: 
Message-ID: <46f0f888-0349-4d77-9a34-18420d70a9b3@a70g2000hsh.googlegroups.com>
On 7 Sep, 21:14, Marco Antoniotti <·······@gmail.com> wrote:
> On Sep 7, 5:55 pm, Tamas K Papp <······@gmail.com> wrote:
>
>
>
> > I frequently find that I need to access a slot of a slot of a slot, etc.  
> > Hence
>
> > (defmacro slot-path (instance &rest path)
> >   "Follow the path of slots starting from instance recursively.  
> > setf'able."
> >   (unless path
> >     (error "empty slot path"))
> >   (labels ((rec-expand (path)
> >              (if path
> >                  (list 'slot-value
> >                        (rec-expand (cdr path))
> >                        (car path))
> >                  instance)))
> >     (rec-expand (reverse path))))
>
> > Example:
>
> > (defclass c-a ()
> >   ((a :initarg :a)))
>
> > (defclass c-b ()
> >   ((b :initarg :b)))
>
> > (defparameter *c* (make-instance 'c-a :a (make-instance 'c-b :b 2)))
> > (slot-path *c* 'a 'b)      ; => 2
> > (setf (slot-path *c* 'a 'b) 4)
> > (slot-path *c* 'a 'b)      ; => 4
>
> > But the name seems a bit weird.  Any suggestions?  Perhaps this already
> > exists somewhere else :-)
>
> > Tamas
>
> If you use readers, this is just COMPOSE.
>
>     (funcall (compose 'reader1 'reader2 ... readerN) object)

That's cool!  Its a great example of how seamlessly the functional and
object
oriented aspects of Lisp can co-exist.

--
Andy
From: Marco Antoniotti
Subject: Re: how would you name this macro?
Date: 
Message-ID: <dd30f6b8-ef22-4ae4-99c5-2e8f4e125c23@m73g2000hsh.googlegroups.com>
On Sep 8, 2:20 pm, Andy Chambers <··············@googlemail.com>
wrote:
> On 7 Sep, 21:14, Marco Antoniotti <·······@gmail.com> wrote:
>
>
>
> > On Sep 7, 5:55 pm, Tamas K Papp <······@gmail.com> wrote:
>
> > > I frequently find that I need to access a slot of a slot of a slot, etc.  
> > > Hence
>
> > > (defmacro slot-path (instance &rest path)
> > >   "Follow the path of slots starting from instance recursively.  
> > > setf'able."
> > >   (unless path
> > >     (error "empty slot path"))
> > >   (labels ((rec-expand (path)
> > >              (if path
> > >                  (list 'slot-value
> > >                        (rec-expand (cdr path))
> > >                        (car path))
> > >                  instance)))
> > >     (rec-expand (reverse path))))
>
> > > Example:
>
> > > (defclass c-a ()
> > >   ((a :initarg :a)))
>
> > > (defclass c-b ()
> > >   ((b :initarg :b)))
>
> > > (defparameter *c* (make-instance 'c-a :a (make-instance 'c-b :b 2)))
> > > (slot-path *c* 'a 'b)      ; => 2
> > > (setf (slot-path *c* 'a 'b) 4)
> > > (slot-path *c* 'a 'b)      ; => 4
>
> > > But the name seems a bit weird.  Any suggestions?  Perhaps this already
> > > exists somewhere else :-)
>
> > > Tamas
>
> > If you use readers, this is just COMPOSE.
>
> >     (funcall (compose 'reader1 'reader2 ... readerN) object)
>
> That's cool!  Its a great example of how seamlessly the functional and
> object
> oriented aspects of Lisp can co-exist.


... and it works for DEFSTRUCTs as well.

--
Marco
From: Madhu
Subject: Re: how would you name this macro?
Date: 
Message-ID: <m3y7227pas.fsf@moon.robolove.meer.net>
* Andy Chambers
| On 7 Sep, 21:14, Marco Antoniotti <> wrote:
|> On Sep 7, 5:55 pm, Tamas K Papp <> wrote:

[Argh. This puts me in ranting angry old man mode!
 I'm sick of google users mangling Email addresses in content!]

|> > I frequently find that I need to access a slot of a slot of a slot, etc.  
|> > Hence
|>
|> > (defmacro slot-path (instance &rest path)
|> >   "Follow the path of slots starting from instance recursively.  
|> > setf'able."
|> >   (unless path
|> >     (error "empty slot path"))
|> >   (labels ((rec-expand (path)
|> >              (if path
|> >                  (list 'slot-value
|> >                        (rec-expand (cdr path))
|> >                        (car path))
|> >                  instance)))
|> >     (rec-expand (reverse path))))

[and I'm sick of google users replacing SPACE with a non-ascii NBSP when
quoting text!]

|> If you use readers, this is just COMPOSE.
|>
|>     (funcall (compose 'reader1 'reader2 ... readerN) object)
|
| That's cool!  Its a great example of how seamlessly the functional and
| object
| oriented aspects of Lisp can co-exist.

Not really. Note Marco restricted the scope to readers.

[oh and i'm sick of google user's funky linebreaking to wrap lines! Oh
the number of mangled URLs!]

Tamas Papp's macro was not just for reading slots but also for writing
them.

|> > (setf (slot-path *c* 'a 'b) 4)
|> > (slot-path *c* 'a 'b)      ; => 4

I'm sure one cant come up with a setf expander for funcall and compose.

--
Madhu
From: Rob Warnock
Subject: Re: how would you name this macro?
Date: 
Message-ID: <o4-dnUB3i-uYqFrVnZ2dnUVZ_gKdnZ2d@speakeasy.net>
Madhu  <·······@meer.net> wrote:
+---------------
| * Andy Chambers
| | On 7 Sep, 21:14, Marco Antoniotti <> wrote:
| |> If you use readers, this is just COMPOSE.
| |> (funcall (compose 'reader1 'reader2 ... readerN) object)
| |
| | That's cool!  Its a great example of how seamlessly the functional
| | and object  oriented aspects of Lisp can co-exist.
| 
| Not really. Note Marco restricted the scope to readers.
+---------------

What's wrong with this, then?

    (setf (writerN (funcall (compose 'reader1 ... readerN-1)) object)
	  new-value)

+---------------
| Tamas Papp's macro was not just for reading slots but also for
| writing them.
| |> > (setf (slot-path *c* 'a 'b) 4)
| |> > (slot-path *c* 'a 'b)      ; => 4
| I'm sure one cant come up with a setf expander for funcall and compose.
+---------------

Why not? Just because FUNCALL is in the COMMON-LISP package?
Most implementations provide ways around that [e.g., wrap the
DEFSETF with a WITHOUT-PACKAGE-LOCKS or equiv.].

And at least in CMUCL, the SETF support is aleady there, were you
to define a #'(SETF FUNCALL) function:

    cmu> (macroexpand
	  '(setf (funcall (compose 'read1 'read2 'write3) obj) newval))
    (LET* ((#:G1585 (COMPOSE 'READ1 'READ2 'WRITE3)) (#:G1584 OBJ))
      (MULTIPLE-VALUE-BIND (#:G1583)
	  NEWVAL
	(FUNCALL #'(SETF FUNCALL) #:G1583 #:G1585 #:G1584)))
    cmu> 


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Marco Antoniotti
Subject: Re: how would you name this macro?
Date: 
Message-ID: <3352c436-b352-4681-892e-3ef526ac7599@m45g2000hsb.googlegroups.com>
On Sep 10, 4:46 am, ····@rpw3.org (Rob Warnock) wrote:
> Madhu  <·······@meer.net> wrote:
>
> +---------------
> | * Andy Chambers
> | | On 7 Sep, 21:14, Marco Antoniotti <> wrote:
> | |> If you use readers, this is just COMPOSE.
> | |> (funcall (compose 'reader1 'reader2 ... readerN) object)
> | |
> | | That's cool!  Its a great example of how seamlessly the functional
> | | and object  oriented aspects of Lisp can co-exist.
> |
> | Not really. Note Marco restricted the scope to readers.
> +---------------
>
> What's wrong with this, then?
>
>     (setf (writerN (funcall (compose 'reader1 ... readerN-1)) object)
>           new-value)
>
> +---------------
> | Tamas Papp's macro was not just for reading slots but also for
> | writing them.
> | |> > (setf (slot-path *c* 'a 'b) 4)
> | |> > (slot-path *c* 'a 'b)      ; => 4
> | I'm sure one cant come up with a setf expander for funcall and compose.
> +---------------
>
> Why not? Just because FUNCALL is in the COMMON-LISP package?
> Most implementations provide ways around that [e.g., wrap the
> DEFSETF with a WITHOUT-PACKAGE-LOCKS or equiv.].
>
> And at least in CMUCL, the SETF support is aleady there, were you
> to define a #'(SETF FUNCALL) function:
>
>     cmu> (macroexpand
>           '(setf (funcall (compose 'read1 'read2 'write3) obj) newval))
>     (LET* ((#:G1585 (COMPOSE 'READ1 'READ2 'WRITE3)) (#:G1584 OBJ))
>       (MULTIPLE-VALUE-BIND (#:G1583)
>           NEWVAL
>         (FUNCALL #'(SETF FUNCALL) #:G1583 #:G1585 #:G1584)))
>     cmu>

Yes.  The above is right.
Actually a cursory reading of the relevant SETF incunabola makes me
think that

    (setf (apply #'w_N
                 (list (funcall (compose r_0 r_1 ... reader_N-1)
obj)))
          new-value)

may be conforming and made working in most implementations.  My
understanding may be flawed...

Cheers
--
Marco
From: Madhu
Subject: Re: how would you name this macro?
Date: 
Message-ID: <m38wu0qdoc.fsf@moon.robolove.meer.net>
[ only mental wanking here, advice skipping unless you're really bored :-} ]

* (Rob Warnock) <································@speakeasy.net> :
Wrote on Tue, 09 Sep 2008 21:46:29 -0500:

| Madhu  <·······@meer.net> wrote:
| +---------------
| | * Andy Chambers
| | | On 7 Sep, 21:14, Marco Antoniotti <> wrote:
| | |> If you use readers, this is just COMPOSE.
| | |> (funcall (compose 'reader1 'reader2 ... readerN) object)
| | |
| | | That's cool!  Its a great example of how seamlessly the functional
| | | and object  oriented aspects of Lisp can co-exist.
| | 
| | Not really. Note Marco restricted the scope to readers.
| +---------------
|
| What's wrong with this, then?
|
|     (setf (writerN (funcall (compose 'reader1 ... readerN-1)) object)
| 	  new-value)

Nothing wrong at all! :-}
[Well actually the argument order to COMPOSE, the way it is notated
above may be wrong.  I think it needs to be reversed, corrected in
the example below]

But if you wanted to compare apples to apples you'd want to arrive at

     (setf (accessor1 (funcall (compose 'accessor2 .. 'accessorN)) object)
            NEW-VALUE)

from translating

     (setf (funcall (compose 'accessor1 ... 'accessorN) object) NEW-VALUE)

Where the OP would have written

     (setf (slot-path object 'slotN ... 'slot2 'slot1) NEW-VALUE)

I assumed the `coolness' which Andy Chambers perceived was coming from
composing function objects directly, by specifying them by listing them
serially -- just like the OP did in his macro --- i.e. not by
rearranging symbols in a macro but manipulating function objects.

| +---------------
| | Tamas Papp's macro was not just for reading slots but also for
| | writing them.
| | |> > (setf (slot-path *c* 'a 'b) 4)
| | |> > (slot-path *c* 'a 'b)      ; => 4
| | I'm sure one cant come up with a setf expander for funcall and compose.
| +---------------

| Why not? Just because FUNCALL is in the COMMON-LISP package?
| Most implementations provide ways around that [e.g., wrap the
| DEFSETF with a WITHOUT-PACKAGE-LOCKS or equiv.].

| And at least in CMUCL, the SETF support is aleady there, were you
| to define a #'(SETF FUNCALL) function:
|
|     cmu> (macroexpand
| 	  '(setf (funcall (compose 'read1 'read2 'write3) obj) newval))
|     (LET* ((#:G1585 (COMPOSE 'READ1 'READ2 'WRITE3)) (#:G1584 OBJ))

^^^ SETF stuffs ALL the accessors into COMPOSE including the
writer.  This isn't right is  it?

|       (MULTIPLE-VALUE-BIND (#:G1583)
| 	  NEWVAL
| 	(FUNCALL #'(SETF FUNCALL) #:G1583 #:G1585 #:G1584)))

This is essentially:

	(funcall (setf funcall) 
            new-value 
            (compose 'accessor1 'accessor2 'accessor3) ;; <- opaque  object!
            obj)

remember what we want to do is 

         (setf (accessor1 (accessor2 (accessor3 obj)))
               new-value)

Can't see how that would be work by writing an expander


So my rules for preserving coolness when extending the scope to setters
1) to list the accessors easily, serially, and 2) manipulating function
objects directly in the syntax.

In a parallel reply Marco suggested:

    (setf (apply #'accessor1
                 (list (funcall (compose accessor2 ... accessorN) obj)))
          new-value)

works out of the box on CMUCL and ACL. But it does not have portable
sanction from the Spec: See 5.1.2.5.  APPLY Forms as Places

--
Madhu :)
From: Stephen Compall
Subject: Re: how would you name this macro?
Date: 
Message-ID: <m21vzvy8la.fsf@nocandy.dyndns.org>
Tamas K Papp <······@gmail.com> writes:
> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
>
> (defmacro slot-path (instance &rest path)

Recently finding myself in a similar situation:

(defmacro of (root &rest accessors)
  "Convenience for digging down into accessors for an object.

Besides the usual path-like semantics, provide a keyword and I will
look for all future symbols in the so-named package before using the
original symbol."
  (let (default-pkg)
    (reduce (lambda (inner accessor)
              (if (keywordp accessor)
                  (progn (setf default-pkg accessor)
                         inner)
                  (list (if default-pkg
                            (multiple-value-bind (sym stat)
                                (find-symbol (symbol-name accessor) default-pkg)
                              (if (eq ':external stat) sym accessor))
                            accessor)
                        inner)))
            accessors :initial-value root)))

Hmm, I seem to have developed the bad habit of saying "besides the usual
X semantics" when unwilling to explain what those semantics are.

-- 
But you know how reluctant paranormal phenomena are to reveal
themselves when skeptics are present. --Robert Sheaffer, SkI 9/2003
From: Joseph Dale
Subject: Re: how would you name this macro?
Date: 
Message-ID: <ga21ge$6j4$1@geode.berkeley.edu>
Tamas K Papp wrote:
> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
> [...]
> 
> But the name seems a bit weird.  Any suggestions?

slot-chain-value
From: Pascal J. Bourguignon
Subject: Re: how would you name this macro?
Date: 
Message-ID: <87zlmjk93d.fsf@hubble.informatimago.com>
Tamas K Papp <······@gmail.com> writes:

> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
>
> (defmacro slot-path (instance &rest path)
>   "Follow the path of slots starting from instance recursively.  
> setf'able."
>   (unless path
>     (error "empty slot path"))
>   (labels ((rec-expand (path)
> 	     (if path
> 		 (list 'slot-value
> 		       (rec-expand (cdr path))
> 		       (car path))
> 		 instance)))
>     (rec-expand (reverse path))))
>
> Example:
>
> (defclass c-a ()
>   ((a :initarg :a)))
>
> (defclass c-b ()
>   ((b :initarg :b)))
>
> (defparameter *c* (make-instance 'c-a :a (make-instance 'c-b :b 2)))
> (slot-path *c* 'a 'b)      ; => 2
> (setf (slot-path *c* 'a 'b) 4)
> (slot-path *c* 'a 'b)      ; => 4
>
> But the name seems a bit weird.  Any suggestions?  Perhaps this already 
> exists somewhere else :-)

Have a look at:

http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/82718221ab08acaa/c5dc91b57b35b82b?lnk=st&q=%22Iteration+objects+structures+conditions%22+site%3Apaste.lisp.org#c5dc91b57b35b82b

It uses the accessor of the object or structure:

  ((typep object '(or structure-object standard-object)) 
     (apply (function ->) (funcall (first path) object) (rest path))) 

but this can easily be changed to use the slot name if you prefer it.
(I'd tend to consider the slot name "private").  Replace the above
clause by these two clauses:

  ((typep object  'structure-object) 
     (apply (function ->) (funcall (first path) object) (rest path))) 
  ((typep object  'standard-object) 
     (apply (function ->) (slot-value object (first path)) (rest path))) 
 
and do similarly in (setf ->).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Jose A. Ortega Ruiz
Subject: Re: how would you name this macro?
Date: 
Message-ID: <877i9nr7kq.fsf@mithrandir.homeunix.net>
Tamas K Papp <······@gmail.com> writes:

> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
>
> (defmacro slot-path (instance &rest path)
>   "Follow the path of slots starting from instance recursively.  
> setf'able."

[...]

>
> But the name seems a bit weird.  Any suggestions?  Perhaps this already 
> exists somewhere else :-)
>

i'd use SLOT* or SLOT-VALUE* (and now you know where i'm coming from),
but i've got the impression that star suffixes are not common in CL
(probably because of the earmuffs convention for specials). is that a
correct impression?

jao
-- 
I always pass on good advice. It's the only thing to do with it. It is
never any use to oneself.
 -Oscar Wilde
From: Stephen Compall
Subject: Re: how would you name this macro?
Date: 
Message-ID: <m2sksbwio3.fsf@nocandy.dyndns.org>
"Jose A. Ortega Ruiz" <···@gnu.org> writes:
> i'd use SLOT* or SLOT-VALUE* (and now you know where i'm coming from),
> but i've got the impression that star suffixes are not common in CL
> (probably because of the earmuffs convention for specials). is that a
> correct impression?

* is common, but not for this; instead, it means one of two things:

 1. This is like that other macro, but binds in sequence instead of
    in parallel.  See do*, let*.

 2. This is like that other macro, but does something different (and I'm
    afraid I can't be more specific, you must look at the macro or
    docstring to know what is different).  See many incompatible
    defclass*.

-- 
But you know how reluctant paranormal phenomena are to reveal
themselves when skeptics are present. --Robert Sheaffer, SkI 9/2003
From: Jose A. Ortega Ruiz
Subject: Re: how would you name this macro?
Date: 
Message-ID: <8763p7ph3l.fsf@mithrandir.homeunix.net>
Stephen Compall <···············@gmail.com> writes:

> "Jose A. Ortega Ruiz" <···@gnu.org> writes:
>> i'd use SLOT* or SLOT-VALUE* (and now you know where i'm coming from),
>> but i've got the impression that star suffixes are not common in CL
>> (probably because of the earmuffs convention for specials). is that a
>> correct impression?
>
> * is common, but not for this; instead, it means one of two things:
>
>  1. This is like that other macro, but binds in sequence instead of
>     in parallel.  See do*, let*.
>
>  2. This is like that other macro, but does something different (and I'm
>     afraid I can't be more specific, you must look at the macro or
>     docstring to know what is different).  See many incompatible
>     defclass*.

it was in sense 2 that i was proposing SLOT-VALUE*: it's like SLOT-VALUE
in that it gets the value of a slot, but does something different in
that it's not a direct slot... although i see that we're using slightly
different meanings of 'different' here :).

anyway, thanks for the clarification.

jao
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."
  -Terry Pratchett, Reaper Man
From: Rainer Joswig
Subject: Re: how would you name this macro?
Date: 
Message-ID: <joswig-15155B.09342608092008@news-europe.giganews.com>
In article <··············@nocandy.dyndns.org>,
 Stephen Compall <···············@gmail.com> wrote:

> "Jose A. Ortega Ruiz" <···@gnu.org> writes:
> > i'd use SLOT* or SLOT-VALUE* (and now you know where i'm coming from),
> > but i've got the impression that star suffixes are not common in CL
> > (probably because of the earmuffs convention for specials). is that a
> > correct impression?
> 
> * is common, but not for this; instead, it means one of two things:
> 
>  1. This is like that other macro, but binds in sequence instead of
>     in parallel.  See do*, let*.
> 
>  2. This is like that other macro, but does something different (and I'm
>     afraid I can't be more specific, you must look at the macro or
>     docstring to know what is different).  See many incompatible
>     defclass*.

3. It does the same like that other macro, but takes slightly
   different arguments. See CLIM:DRAW-LINE vs. CLIM:DRAW-LINE* .
   The first takes point objects and the second takes numeric 
   coordinate values.

...

-- 
http://lispm.dyndns.org/
From: Thomas A. Russ
Subject: Re: how would you name this macro?
Date: 
Message-ID: <ymiabei8vhm.fsf@blackcat.isi.edu>
Tamas K Papp <······@gmail.com> writes:

> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
> 
> (defmacro slot-path (instance &rest path)
>   "Follow the path of slots starting from instance recursively.  
> setf'able."
....

Well, my preferred approach would be to use accessor methods instead of
SLOT-VALUE.  In that case, there really isn't any need to have a
SLOT-PATH macro, since

  (slot-path i 'slot1 'slot2 'slot3)

doesn't seem to give any clarity or code length advantage over

  (slot3 (slot2 (slot1 i)))


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Wade
Subject: Re: how would you name this macro?
Date: 
Message-ID: <c258e7ce-c0d4-4154-ba4d-e6c1821ef0ab@s50g2000hsb.googlegroups.com>
I would probably just name it @slots

(defmacro @slots (instance &rest path)
  (if path
      `(@slots (slot-value ,instance ,(car path)) ,@(cdr path))
      instance))

Wade
From: Marco Antoniotti
Subject: Re: how would you name this macro?
Date: 
Message-ID: <e8f69e76-1c00-49bd-bbde-9a92b2d40b67@y21g2000hsf.googlegroups.com>
On Sep 9, 3:35 am, Wade <·············@gmail.com> wrote:
> I would probably just name it @slots
>
> (defmacro @slots (instance &rest path)
>   (if path
>       `(@slots (slot-value ,instance ,(car path)) ,@(cdr path))
>       instance))
>

Nahhhh!  Way too Perlish!  There is a convention used in CLIM of
adding just one earmuff to denote function variants.  I vote for SLOT-
VALUE*.

Cheers
--
Marco
From: Kaz Kylheku
Subject: Re: how would you name this macro?
Date: 
Message-ID: <20080908121718.653@gmail.com>
On 2008-09-07, Tamas K Papp <······@gmail.com> wrote:
> I frequently find that I need to access a slot of a slot of a slot, etc.  
> Hence
>
> (defmacro slot-path (instance &rest path)
>   "Follow the path of slots starting from instance recursively.  

This is a special case of a left-to-right ``filtering'' alternative syntax to
nested function calls.

I posted a FILTER macro here some years ago.

If you have accessor functions called A, B, C, D., then you end up with
something like:

  (D (C (B (A OBJ))))

which can be transformed by the FILTER macro to:

  (FILTER OBJ A B C D)

FILTER could be extended with some shorthand for SLOT-VALUE, for cases
when you don't have the read accessors.

SLOT-PATH is too specific to slot access. What if something other than slot
access is required in the middle of the chain to continue it? Suppose that
accessor B pulls out an array, and the zeroth element must be pulled out:

  ;; like OBJ.A.B[0].C in some other language

  (FILTER OBJ A B (AREF _ 0) C D)

The (AREF _ 0) relies on currying in the non-trailing position, a feature of
the FILTER macro.

SETF-ability would take a bit of work in the FILTER macro implementation; I see
now that it had been short-sighted not to have made it a design requirement.