From: Michael J. Conroy
Subject: getf and setq
Date: 
Message-ID: <QLg4a.2973$7V1.351184037@newssvr10.news.prodigy.com>
Quick question:

If I do this:

(setf temp '("foo" 1 "bar" 2))
    ("foo" 1 "bar" 2)

and then...

(getf temp '"foo")
    (NIL)

?????

Why doesn't getf handle the double quotes?

From: Paul F. Dietz
Subject: Re: getf and setq
Date: 
Message-ID: <3E519B5F.6070006@dls.net>
Michael J. Conroy wrote:
> Quick question:
> 
> If I do this:
> 
> (setf temp '("foo" 1 "bar" 2))
>     ("foo" 1 "bar" 2)
> 
> and then...
> 
> (getf temp '"foo")
>     (NIL)
> 
> ?????
> 
> Why doesn't getf handle the double quotes?

GETF's searches for a property whose property
is 'identical' to the indicator.  The two "foo"
strings there are not 'identical' (the same under EQ).

	Paul
From: Kaz Kylheku
Subject: Re: getf and setq
Date: 
Message-ID: <cf333042.0302181155.73f15e1e@posting.google.com>
"Michael J. Conroy" <········@snet.net> wrote in message news:<························@newssvr10.news.prodigy.com>...
> Why doesn't getf handle the double quotes?

This is not a quick question at all. You are laboring under some
serious confusion between a data structure and its printed
representation. A string object does not contain double quotes, any
more than does a list contain parentheses.

Symbols and strings are different beasts; a string is not just a
symbol that is written in double quotes. A symbol is an atom; an
object which is primarily interesting because of its unique identity.
A string is a vector of characters. A symbol has a name property which
is a string object, but a symbol is not that name.

The GETF function is intended for accessing a property list. The
property list contains indicators and values. The indicator specified
in GETF is compared to the list's indicators using the EQ function: in
other words, an identity test is used. For a match to occur, the
specified indicator must in fact be the *same object* as one of the
indicators in the list.

Strings cannot be reliably compared with EQ; to test whether two
strings contain the same sequence of characters, use EQUAL (or
STRING=). A case-insensitive comparison can be done using EQUALP or
STRING-EQUAL.

You can't override the function that GETF uses for comparing
indicators, so if you want a lookup structure keyed on strings, you
can't use a property list. Use a hash table instead: see the
MAKE-HASH-TABLE function.
From: Coby Beck
Subject: Re: getf and setq
Date: 
Message-ID: <b2s6kk$2h4m$1@otis.netspace.net.au>
"Michael J. Conroy" <········@snet.net> wrote in message
·····························@newssvr10.news.prodigy.com...
> Quick question:
>
> If I do this:
>
> (setf temp '("foo" 1 "bar" 2))
>     ("foo" 1 "bar" 2)
>
> and then...
>
> (getf temp '"foo")
>     (NIL)
>
> ?????
>
> Why doesn't getf handle the double quotes?

Firstly, if you want (getf <var> <property-indicator>) to return something,
you will have to first (setf (getf <var> <property-indicator>) <value>)

CL-USER 6 > (defvar foo nil)
FOO

CL-USER 7 > (setf (getf foo "foo") 1)
1

CL-USER 8 > (getf foo "foo")
NIL

This still did not work because the property indicator used to retrieve the
property must be identical to the one used in setting it.  This means EQ,
and literal strings are not defined to be so.  You can instead use symbols:

CL-USER 9 > (setf (getf foo 'foo) 1)
1

CL-USER 10 > (getf foo 'foo)
1

or if it really is strings you must use, do something like this:

CL-USER 11 > (defvar p "foo")
P

CL-USER 12 > (setf (getf foo p) 1)
1

CL-USER 13 > (getf foo p)
1

But beware:

CL-USER 14 > (defvar p2 "foo")
P2

CL-USER 15 > (getf foo p2)
NIL

CL-USER 16 > (setf p2 p)
"foo"

CL-USER 17 > (getf foo p2)
1

CL-USER 18 > (setf p2 (copy-seq p))
"foo"

CL-USER 19 > (getf foo p2)
NIL


--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Larry Clapp
Subject: Re: getf and setq
Date: 
Message-ID: <tkbt2b.ij8.ln@theclapp.ddts.net>
In article <·············@otis.netspace.net.au>, Coby Beck wrote:
> "Michael J. Conroy" <········@snet.net> wrote in message
> ·····························@newssvr10.news.prodigy.com...
>> Quick question:
>>
>> If I do this:
>>
>> (setf temp '("foo" 1 "bar" 2))
>>     ("foo" 1 "bar" 2)
>>
>> and then...
>>
>> (getf temp '"foo")
>>     (NIL)
>>
>> ?????
>>
>> Why doesn't getf handle the double quotes?
> 
> Firstly, if you want (getf <var> <property-indicator>) to return
> something, you will have to first (setf (getf <var>
> <property-indicator>) <value>)

Minor quibble: not true.  His code works if you use, say, keywords:

    * (let (temp)
	(values
	  (setf temp '(:foo 1 :bar 2))
	  (getf temp :foo)))
    => (:FOO 1 :BAR 2)
    => 1

Perhaps you're thinking of plain old GET?

    * (get 'temp :foo)
    => NIL
    * (setf (get 'temp :foo) 3)
    => 3
    * (get 'temp :foo)
    => 3

-- 
Larry Clapp / ·····@theclapp.org
Use Lisp from Vim: VILisp: http://vim.sourceforge.net/script.php?script_id=221


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Coby Beck
Subject: Re: getf and setq
Date: 
Message-ID: <b2ubst$14pc$1@otis.netspace.net.au>
"Larry Clapp" <·····@theclapp.org> wrote in message
··················@theclapp.ddts.net...
> In article <·············@otis.netspace.net.au>, Coby Beck wrote:
> > "Michael J. Conroy" <········@snet.net> wrote in message
> > ·····························@newssvr10.news.prodigy.com...
> >> Quick question:
> >>
> >> If I do this:
> >>
> >> (setf temp '("foo" 1 "bar" 2))
> >>     ("foo" 1 "bar" 2)
> >>
> >> and then...
> >>
> >> (getf temp '"foo")
> >>     (NIL)
> >>
> >> ?????
> >>
> >> Why doesn't getf handle the double quotes?
> >
> > Firstly, if you want (getf <var> <property-indicator>) to return
> > something, you will have to first (setf (getf <var>
> > <property-indicator>) <value>)
>
> Minor quibble: not true.  His code works if you use, say, keywords:
>
>     * (let (temp)
> (values
>   (setf temp '(:foo 1 :bar 2))
>   (getf temp :foo)))
>     => (:FOO 1 :BAR 2)
>     => 1
>
> Perhaps you're thinking of plain old GET?

Indeed I was.  Thanks for the correction.  I have never used GETF before but
now I can't wait for a good opportunity ;)

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")