So I was writing some generic functions and methods and I ran into
this thing that confused me:
First I defined a generic function:
(defgeneric (setf utc) (clock utc))
Then I defined a method:
(defmethod (setf utc) ((clock system-clock) utc) (some-stuff))
However I discovered that when I say:
(setf (utc my-clock) 10)
the arguments are passed as (10 my-clock) not (my-clock 10) as I was
expecting. (Which I discovered because I had no method specalized on
(fixnum system-clock) So it's no big news that my expectations were
wrong--I am but an egg. But now I can't for the life of me find where
in the CLHS I should have read to have known the order of the
arguments to the function. I looked under setf, defun, defmethod,
defsetf, and elsewhere.
Can someone point me to the appropriate chapter and verse?
-Peter
--
Peter Seibel
·····@javamonkey.com
Peter Seibel <·····@javamonkey.com> writes:
> But now I can't for the life of me find where in the CLHS I
> should have read to have known the order of the arguments to
> the function. I looked under setf, defun, defmethod, defsetf,
> and elsewhere.
>
> Can someone point me to the appropriate chapter and verse?
The documentation of SETF says
# For detailed treatment of the expansion of setf and psetf, see
# Section 5.1.2 (Kinds of Places).
There we find
# 5.1.2.9 Other Compound Forms as Places
which will answer the question.
Regards,
--
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.
PGP key ID #xD26EF2A0
Nils Goesche <···@cartan.de> writes:
> Peter Seibel <·····@javamonkey.com> writes:
>
> > But now I can't for the life of me find where in the CLHS I
> > should have read to have known the order of the arguments to
> > the function. I looked under setf, defun, defmethod, defsetf,
> > and elsewhere.
> >
> > Can someone point me to the appropriate chapter and verse?
>
> The documentation of SETF says
>
> # For detailed treatment of the expansion of setf and psetf, see
> # Section 5.1.2 (Kinds of Places).
>
> There we find
>
> # 5.1.2.9 Other Compound Forms as Places
>
> which will answer the question.
Cool. Thanks.
-Peter
--
Peter Seibel
·····@javamonkey.com
In article <··············@localhost.localdomain>,
Peter Seibel <·····@javamonkey.com> wrote:
>However I discovered that when I say:
>
> (setf (utc my-clock) 10)
>
>the arguments are passed as (10 my-clock) not (my-clock 10) as I was
>expecting.
Someone else already pointed you to the chapter and verse that documents
this. But here's how you can remember it intuitively: There can be
arbitrary many parameters in the place, even &key and &rest parameters, but
there's only one new-value. It would make no sense for the new-value to be
after &rest parameters. It's always in the same place for all setf
functions, and therefore the only reasonable place is as the first
parameter.
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.