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

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

bug#64960: Documentation for copy-sequence


From: Drew Adams
Subject: bug#64960: Documentation for copy-sequence
Date: Mon, 31 Jul 2023 01:36:49 +0000

> > > A string doesn't share anything because characters are not reference
> > > values. They are simply copied.
> >
> >
> > Yes and no.
> > Chars are not shared, but char properties are.
> >
> > (setq foo (propertize "abcd" 'p1 t 'p2 42))
> > ;; -> #("abcd" 0 4 (p2 42 p1 t))
> > (setq bar (copy-sequence foo))
> > ;; -> #("abcd" 0 4 (p1 t p2 42))
> > (aset foo 1 ?W) ; -> ?W, aka 87
> > foo ; -> #("aWcd" 0 4 (p2 42 p1 t))
> > bar ; -> #("abcd" 0 4 (p1 t p2 42))
> 
> Ok, meaning that the actual string becomes different, yet changing
> the a property, changes the property on both foo and bar ?

No.  I didn't change a property.  I swapped one
char for another.  The doc says that the arg's
"elements" are shared.  A string's "elements"
are its chars.  But as Yuri pointed out, the
chars themselves aren't shared, because they
aren't sharable: they aren't references.

Strings can also have properties.  We sometimes
say that it's the characters that have the
properties, but really it's that the properties
are attached to the characters in the string or
buffer - the properties are associated with
string or buffer positions.  The chars themselves
don't really have properties.  The properties are
shared when you copy a string; the chars are not.

This is really more of a natural-language nuance,
about what it means for string elements to be
shared.  You can ignore it, if what I'm saying
just confuses things.


reply via email to

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