help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "push" creating circular objects


From: Nikolaj Schumacher
Subject: Re: "push" creating circular objects
Date: Sat, 23 Aug 2008 13:43:56 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin)

Charles Sebold <address@hidden> wrote:

>> Also, how about consing up the strings with (string ?u ?l) or somesuch
>> to avoid 'em being treated as the same?
>
> I'll give that a try... yeah, that fixed it.  I'm surprised I have to do
> this, though.  Why are they being treated as the same?

Because they /are/ the same.  A string in your code is a constant.  A
reference, not a copy, is returned each time.

> Knowing this, I replaced (string ?u ?l) with (copy-sequence "ul") and so
> forth, and got the same result.
>
> Thanks very much for this.  But I'm surprised I have to do it.

You don't have to do it.  As long as you treat the strings as read-only,
you're fine.  It's generally a good idea never to manipulate strings
directly:

(defun get-a-string ()
  "ab")

(get-a-string) => "ab"

(aset (get-a-string) 0 ?b)

(get-a-string) => "bb" (!)



regards,
Nikolaj Schumacher




reply via email to

[Prev in Thread] Current Thread [Next in Thread]