[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Newbie strange defun syntax

Jacek Grzebyta

11/24/2015 2:08:00 PM

Hi All,

I found in /UniversalConfig/ package within =access.lisp= file following defun expression:

(defun (setf config-tree) (value &rest accessors) ...)

What does it mean? What is function's name then? Is it "setf config-tree" or it is returned
(??) by "setf config-tree" expression? There is already defined =config-tree= function
so I guess they are somehow related to each other.

Thanks a lot,

Jacek
12 Answers

usenet

6/17/2012 12:14:00 AM

0

In article
<52f071d5-2809-49ab-9a7f-ae2015b2645f@j10g2000yqd.googlegroups.com>,
fanabba <fana...@aol.com> posted:
>
> On Jun 16, 9:41=A0am, arah <araharah2...@gmail.com> wrote:
> > THE MESSAGE OF FALSE RELIGION
> > . . .
>
> Please stop this nonsense.
>
> The world needs to be made aware of genocidal acts of Muslims and
> Islam against Jews, Hindus, the Ottoman Greeks, Armenian Christians,
> and Africans. Tears of Jihad
>
> http://www.politicalislam.com/blog/tears...
>
> The world needs to be made aware of the enslavement by Muslims and
> Islam of Jews, Hindus, white Christians, and black Africans.
>
> The Submission of Women and Slaves in Islam
>
> http://www.amazon.com/The-Submission-Women-Slaves-Editor/dp/0979579406/ref=sr_1_5?s=books&ie=UTF8&qid=1337594968&...
>
> Islam cannot be reformed.
>
> Prophet of Doom
>
> http://www.propheto...
>
> Former Muslims Tell the Truth About Islam
> http://www.islam-...
> http://www.faithfr...

Dhanyavaad for your post!

Islam is a terrorist cult.

Jai Maharaj, Jyotishi
Om Shanti

o o o

About the terrorist Goon Squad:

"Myself, Mallu. Yourself?" (V. Bhattathiri)
<KalluMallu123@gmail.com> tries his best to be a bully --
telling others what and when to post, where to post and
where not to post, deliberately publishing lies about
others, stalking and abusing them with hate speech -- but
fails miserably. He is really stressed out, and like his
lap dog Prem Thomas (who currently posts as "P. Rajah"
<user@this.com>, and issues *death threats* to people),
is priming himself for conditions such as stroke and
heart disease. Others in the Goon Squad include
Dayashankar M. Joshi "DMJoshi" <joshidm@gmail.com> who
displays unquestioning obedience to Goon Squad thugs, and
the instigator who posts as "Bholu" <bholu@hotmail.com>

The Goon Squad currently posts most of their abuse
through eternal-september.org and by writing someone
else's name or handle in the "From:" header -- their
favorite now is "fanabbba@gmail.com" (note the extra "b"
and "gmail.com") to make it appear as if the posts are
from "fanabba@aol.com", who has been a regular poster for
many years.
-Updated on February 2, 2012-

Barry Margolin

11/24/2015 3:57:00 PM

0

In article <87si3vbidw.fsf@jacek.org>,
Jacek Grzebyta <jgrzebyta@users.sourceforge.net> wrote:

> Hi All,
>
> I found in /UniversalConfig/ package within =access.lisp= file following
> defun expression:
>
> (defun (setf config-tree) (value &rest accessors) ...)
>
> What does it mean? What is function's name then? Is it "setf config-tree" or
> it is returned
> (??) by "setf config-tree" expression? There is already defined =config-tree=
> function
> so I guess they are somehow related to each other.

(setf config-tree) is the name of the function. A function name can be
either a symbol or a list of the form (setf <symbol>).

It's defining the function that gets called when you do:

(setf (config-tree <something>) <value>)

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

rpw3

11/24/2015 4:35:00 PM

0

Jacek Grzebyta <jgrzebyta@users.sourceforge.net> wrote:
+---------------
| I found in /UniversalConfig/ package within =access.lisp=
| file following defun expression:
|
| (defun (setf config-tree) (value &rest accessors) ...)
|
| What does it mean? What is function's name then?
| Is it "setf config-tree" or it is returned(??) by
| "setf config-tree" expression? There is already
| defined =config-tree= function so I guess they are
| somehow related to each other.
+---------------

Yes, the function's name really *is* actually the
list (SETF CONFIG-TREE). The TL;DR is that this is
a simple way to define a SETF expander for places
referenced by the CONFIG-TREE accessor.

For the next level of detail, see:

http://www.lispworks.com/documentation/HyperSpec/Body/...
5.1.2.9 Other Compound Forms as Places

which shows what (SETF (F ARGS...) NEW-VALUE) expands into,
namely, approximately (FUNCALL #'(SETF F) NEW-VALUE ARGS...).

[That is, assuming F is *not* one of the special/builtin
cases already defined in the preceding sections, particularly
"5.1.2.2 Function Call Forms as Places"],

And for the *next* level down the rabbit hole, you'll want
to start with the glossary entry for "function name":

http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#fun...
...
function name n. 1. (in an environment) A symbol or a
list (SETF symbol) that is the name of a function in
that environment. 2. A symbol or a list (SETF symbol).

and then read all of the sections on "places" and "generalized
reference":

http://www.lispworks.com/documentation/HyperSpec/Bod...
5.1 Generalized Reference
5.1.1 Overview of Places and Generalized Reference
5.1.2 Kinds of Places
5.1.3 Treatment of Other Macros Based on SETF

particularly the definitions of DEFSETF and DEFINE-SETF-EXPANDER.

Bottom line [as I understand it, which isn't all that great]:

0. A list of the form (SETF symbol) *can* be the name of a function.

1. The short form of DEFSETF is a simple way to define a SETF
setter, but the setter function has to be willing to take
the new value *last* in its arg list:

> (defsetf foo foo-setter) ; FOO-SETTER is defined elsewhere.

FOO
> (macroexpand '(setf (foo x y z) val))

(FOO-SETTER X Y Z VAL)
T
>

Note that since the new value comes *last* in this case,
dealing with optional/keyword args can be problematic.

[Yes, the long form of DEFSETF (q.v.) makes it easier to
handle optional/keyword args, but I've never been exactly
sure when you'd want to use it, given the next choice...]

2. (DEFUN (SETF F) ...) is also pretty simple, and similar to
the short DEFSETF version, except that with (DEFUN (SETF F) ...)
the new value is the *first* arg in the call to #'(SETF FOO).
This makes it easier to have optional and/or variable-length
accessor arguments, e.g.:

> (defun (setf foo) (new &rest args)
:blah-blah-blah ; Whatever is needed
new) ; *Required*, to preserve the semantics of SETF.

(SETF FOO)
> (macroexpand '(setf (foo x y z) val))

(LET* ((#:G1584 X) (#:G1583 Y) (#:G1582 Z))
(MULTIPLE-VALUE-BIND (#:G1581)
VAL
(FUNCALL #'(SETF FOO) #:G1581 #:G1584 #:G1583 #:G1582)))
T
>

[Note that in this simple case this is equivalent to just
(FUNCALL #'(SETF FOO) VAL X Y Z).]

3. DEFINE-SETF-EXPANDER is the most complex to use, but
can do *anything* that a SETF can do, including cases
that need to do complex destructering of the arguments.

[I'm sure the other denizens of the group will correct my
CLHS-fu as needed.]


-Rob

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Jacek Grzebyta

11/24/2015 5:38:00 PM

0


I found it working in some mock example.
It seems it is a simple way for making a proxy method
for getting/setting values into object's accessors for example.

Thanks a lot,
Jacek



Barry Margolin <barmar@alum.mit.edu> writes:

> In article <87si3vbidw.fsf@jacek.org>,
> Jacek Grzebyta <jgrzebyta@users.sourceforge.net> wrote:
>
>> Hi All,
>>
>> I found in /UniversalConfig/ package within =access.lisp= file following
>> defun expression:
>>
>> (defun (setf config-tree) (value &rest accessors) ...)
>>
>> What does it mean? What is function's name then? Is it "setf config-tree" or
>> it is returned
>> (??) by "setf config-tree" expression? There is already defined =config-tree=
>> function
>> so I guess they are somehow related to each other.
>
> (setf config-tree) is the name of the function. A function name can be
> either a symbol or a list of the form (setf <symbol>).
>
> It's defining the function that gets called when you do:
>
> (setf (config-tree <something>) <value>)

Kalle Olavi Niemitalo

11/25/2015 12:40:00 AM

0

rpw3@rpw3.org (Rob Warnock) writes:

> 3. DEFINE-SETF-EXPANDER is the most complex to use, but
> can do *anything* that a SETF can do, including cases
> that need to do complex destructering of the arguments.

(defun (setf FOO) ...) supports (setf (apply #'FOO ...) VALUE)
but (define-set-expander FOO ...) cannot do that. The setf
expander has so much control over the arguments that there is not
enough left for APPLY.

Related: <news:87y8i1yjus.fsf@Astalo.kon.iki.fi> from 20 Oct 2004.

rpw3

11/25/2015 12:41:00 PM

0

Kalle Olavi Niemitalo <kon@iki.fi> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > 3. DEFINE-SETF-EXPANDER is the most complex to use, but
| > can do *anything* that a SETF can do, including cases
| > that need to do complex destructering of the arguments.
|
| (defun (setf FOO) ...) supports (setf (apply #'FOO ...) VALUE)
| but (define-set-expander FOO ...) cannot do that. The setf
| expander has so much control over the arguments that there is not
| enough left for APPLY.
|
| Related: <news:87y8i1yjus.fsf@Astalo.kon.iki.fi> from 20 Oct 2004.
+---------------

Thanks!! Your list comparing macros, (SETF foo) functions,
short DEFSETF, long DEFSETF, and DEFINE-SETF-EXPANDER was
*much* more extensive than mine.

Jacek, you should go read Kalle's article, too. [Yes, it's
still accessible in Google Groups, if you bash on the search
function hard enough! ;-} ] His bottom line:

I have been using setf functions and DEFINE-SETF-EXPANDER
but not DEFSETF. If I have understood the features of
DEFSETF correctly, the short form of DEFSETF has no
advantages over a setf function, and the long form of
DEFSETF is only useful if you are defining a place where
multiple values can be stored.


-Rob

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Kaz Kylheku

11/25/2015 3:48:00 PM

0

On 2015-11-25, Rob Warnock <rpw3@rpw3.org> wrote:
> Kalle Olavi Niemitalo <kon@iki.fi> wrote:
> +---------------
>| rpw3@rpw3.org (Rob Warnock) writes:
>| > 3. DEFINE-SETF-EXPANDER is the most complex to use, but
>| > can do *anything* that a SETF can do, including cases
>| > that need to do complex destructering of the arguments.
>|
>| (defun (setf FOO) ...) supports (setf (apply #'FOO ...) VALUE)
>| but (define-set-expander FOO ...) cannot do that. The setf
>| expander has so much control over the arguments that there is not
>| enough left for APPLY.
>|
>| Related: <news:87y8i1yjus.fsf@Astalo.kon.iki.fi> from 20 Oct 2004.
> +---------------
>
> Thanks!! Your list comparing macros, (SETF foo) functions,
> short DEFSETF, long DEFSETF, and DEFINE-SETF-EXPANDER was
> *much* more extensive than mine.
>
> Jacek, you should go read Kalle's article, too. [Yes, it's
> still accessible in Google Groups, if you bash on the search
> function hard enough! ;-} ] His bottom line:
>
> I have been using setf functions and DEFINE-SETF-EXPANDER
> but not DEFSETF. If I have understood the features of
> DEFSETF correctly, the short form of DEFSETF has no
> advantages over a setf function, and the long form of
> DEFSETF is only useful if you are defining a place where
> multiple values can be stored.

The advantage of defsetf is that it uses an any function you want for the store
form. If you have such a function already, chances are it's not called
(setf whatever). You don't have to write an additional function which
duplicates or wraps it.

Jacek Grzebyta

11/27/2015 11:34:00 PM

0

Kaz Kylheku <kaz@kylheku.com> writes:

> On 2015-11-25, Rob Warnock <rpw3@rpw3.org> wrote:
>> Kalle Olavi Niemitalo <kon@iki.fi> wrote:
>> +---------------
>>| rpw3@rpw3.org (Rob Warnock) writes:
>>| > 3. DEFINE-SETF-EXPANDER is the most complex to use, but
>>| > can do *anything* that a SETF can do, including cases
>>| > that need to do complex destructering of the arguments.
>>|
>>| (defun (setf FOO) ...) supports (setf (apply #'FOO ...) VALUE)
>>| but (define-set-expander FOO ...) cannot do that. The setf
>>| expander has so much control over the arguments that there is not
>>| enough left for APPLY.
>>|
>>| Related: <news:87y8i1yjus.fsf@Astalo.kon.iki.fi> from 20 Oct 2004.
>> +---------------
>>
>> Thanks!! Your list comparing macros, (SETF foo) functions,
>> short DEFSETF, long DEFSETF, and DEFINE-SETF-EXPANDER was
>> *much* more extensive than mine.
>>
>> Jacek, you should go read Kalle's article, too. [Yes, it's
>> still accessible in Google Groups, if you bash on the search
>> function hard enough! ;-} ] His bottom line:
>>
>> I have been using setf functions and DEFINE-SETF-EXPANDER
>> but not DEFSETF. If I have understood the features of
>> DEFSETF correctly, the short form of DEFSETF has no
>> advantages over a setf function, and the long form of
>> DEFSETF is only useful if you are defining a place where
>> multiple values can be stored.
>
> The advantage of defsetf is that it uses an any function you want for the store
> form. If you have such a function already, chances are it's not called
> (setf whatever). You don't have to write an additional function which
> duplicates or wraps it.

Thanks a lot to everyone. I see Common Lisp is more like human language
learning: There are quite simple basic rules and complex tips, tricks and
nuances.


Jacek Grzebyta

Jacek Grzebyta

11/27/2015 11:41:00 PM

0


By the way. Can you see my fill name in the "summary page"?
I use gnus as a clien and I can see your names but not mine.
I am not sure if I misconfigured anyhing.

Jacek

rpw3

11/28/2015 1:17:00 AM

0

Jacek Grzebyta <jgrzebyta@users.sourceforge.net> wrote:
+---------------
| By the way. Can you see my fill name in the "summary page"?
| I use gnus as a clien and I can see your names but not mine.
| I am not sure if I misconfigured anyhing.
+---------------

Looks fine from here. [I assume you really meant
"full name", not "fill name", yes?]

I read news with "trn", which presents articles in a
format very similar to email: RFC822-style header lines,
a blamk line, then the body text. The key headers I see
in your message [the one I'm replying to here] were:

Newsgroups: comp.lang.lisp
Date: Fri, 27 Nov 2015 23:41:11 +0000
From: Jacek Grzebyta <jgrzebyta@users.sourceforge.net>
Subject: Re: Newbie ... not related to subject
Message-ID: <87egfbqaco.fsf_-_@jacek.org>
Organization: Aioe.org NNTP Server
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Content-Type: text/plain


-Rob

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403