Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting a property in a symbol.

130 views
Skip to first unread message

Juan Pardillos

unread,
May 26, 2002, 6:48:23 AM5/26/02
to
Hello,

I'd like to know if there is possible in Lisp distinguish between a
situation in which a symbol has a property with nil value and a
situation in which a symbol has not such a property.

As far as I know, (get 'mySymbol 'myProperty) will return nil whether
we did before (set 'mySymbol 'myProperty nil) or no.

Any ideas?.

Thanks in advance

Adam Warner

unread,
May 26, 2002, 7:07:57 AM5/26/02
to

http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_get.htm

There is no way using get to distinguish an absent property from one
whose value is default. However, see get-properties.

http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_get_pr.htm#get-properties

get-properties is used to look up any of several property list entries
all at once.

It searches the plist for the first entry whose indicator is identical
to one of the objects in indicator-list. If such an entry is found, the
indicator and value returned are the property indicator and its
associated property value, and the tail returned is the tail of the
plist that begins with the found entry (i.e., whose car is the
indicator). If no such entry is found, the indicator, value, and tail
are all nil.

Regards,
Adam

Erik Naggum

unread,
May 26, 2002, 10:05:58 AM5/26/02
to
* Adam Warner

| There is no way using get to distinguish an absent property from one
| whose value is default.

Yes, there is. Let the default value be a fresh or unique object. This
is pretty obvious, so a much better solution to the whole problem is this
shadowing redefinition of the standard function:

(shadow 'get)
(defun get (symbol property &optional default)
(let* ((fresh (cons t t))
(prop (cl:get symbol property fresh)))
(if (eq fresh prop)
(values default nil)
(values prop t))))

If this function should not cons, wrap (cons t t) in a load-time-value.
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

70 percent of American adults do not understand the scientific process.

Adam Warner

unread,
May 26, 2002, 10:28:13 AM5/26/02
to
On Mon, 27 May 2002 02:05:58 +1200, Erik Naggum wrote:

> * Adam Warner
> | There is no way using get to distinguish an absent property from one |
> whose value is default.
>
> Yes, there is.

Please tell that to the ANSI Common Lisp specification then Erik. That's
where the sentence comes from.

Regards,
Adam

Erik Naggum

unread,
May 26, 2002, 10:47:45 AM5/26/02
to
* Adam Warner

| Please tell that to the ANSI Common Lisp specification then Erik.

Please read the rest of my article, Adam. I have actually tried to
answer your problem and point to a solution. I have implicitly asked you
to think. Now I ask you explicitly: If you insist on behaving stupidly,
I must conclude that you are no longer interested in a solution, if you
ever where, but in arguing and quibbling. I am interested in solving
problems, but some people are so dead set on being personally "right"
that they lose track of their problem. Which is more important to you:
Having _been_ right by insisting on your past understanding or _becoming_
right by learning and thinking? If you do not display some evidence of
actual thinking if you choose to respond, you will get the last word.

Adam Warner

unread,
May 26, 2002, 12:00:24 PM5/26/02
to
On Mon, 27 May 2002 02:47:45 +1200, Erik Naggum wrote:

> * Adam Warner
> | Please tell that to the ANSI Common Lisp specification then Erik.
>
> Please read the rest of my article, Adam. I have actually tried to
> answer your problem and point to a solution. I have implicitly asked
> you to think. Now I ask you explicitly: If you insist on behaving
> stupidly, I must conclude that you are no longer interested in a
> solution, if you ever where, but in arguing and quibbling. I am
> interested in solving problems, but some people are so dead set on
> being personally "right" that they lose track of their problem. Which
> is more important to you: Having _been_ right by insisting on your
> past understanding or _becoming_ right by learning and thinking? If
> you do not display some evidence of actual thinking if you choose to
> respond, you will get the last word.

Thank you for your ingenious solution Erik. I guess I just got a little
hurt since you called my previous reply bogus when it was a fair attempt
by someone new to Lisp (-like languages) to compare it with Scheme.

My main attempt in this thread was to point out where some of the
"solutions" can be found in the HyperSpec. I am yet to use `get' myself!

I didn't appreciate the condescending reply. It's not endearing. But I've
read enough of the archives to expect it. Perhaps I subconsciously just
wanted to get it over with :-)

Regards,
Adam

Erik Naggum

unread,
May 26, 2002, 1:19:39 PM5/26/02
to
* Adam Warner <use...@consulting.net.nz>

| Thank you for your ingenious solution Erik. I guess I just got a little
| hurt since you called my previous reply bogus when it was a fair attempt
| by someone new to Lisp (-like languages) to compare it with Scheme.

Well, I think comparing Common Lisp to Scheme is prima facie evidence of
ill will, even if Common Lisp wins. It is somewhat like a supposed
compliment like "man, you are even smarter than George W. Bush".

| I didn't appreciate the condescending reply.

No condescension was intended. Brevity, perhaps even harshness, but no
condescension.

| It's not endearing. But I've read enough of the archives to expect it.
| Perhaps I subconsciously just wanted to get it over with :-)

Unfortunately, this is more common than _my_ actually being nasty to
anyone. The sort of preparatory defense in case I hurt someone is even
more idiotic than the things I generally get pissed off by, but I am very
happy that you are aware of some weak tendencies in that direction and
chose to respond differently. Thank you.

Donald Fisk

unread,
May 26, 2002, 5:20:39 PM5/26/02
to

Yes. Use symbol-plist, or a function which calls it:

[1]> (symbol-plist 'foo)
NIL
[2]> (get 'foo 'bar)
NIL
[3]> (setf (get 'foo 'bar) nil)
NIL
[4]> (symbol-plist 'foo)
(BAR NIL)
[5]> (get 'foo 'bar)
NIL

> Thanks in advance

--
Le Hibou
You know you've been hacking too long if, when someone
asks you if you have a son, you reply, "No, but I've
got a Symbolics 3630".

0 new messages