From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Why does using aset sometimes output raw bytes?
Date: Mon, 10 Dec 2018 07:59:52 +0200 [thread overview]
Message-ID: <83in013orr.fsf@gnu.org> (raw)
In-Reply-To: <jwvk1ki2yf1.fsf-monnier+gmane.emacs.help@gnu.org> (message from Stefan Monnier on Sun, 09 Dec 2018 16:20:59 -0500)
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Sun, 09 Dec 2018 16:20:59 -0500
>
> >> It's not the implementation, but the semantics of unibyte/multibyte
> >> strings presumes that the difference doesn't matter much for ASCII-only
> >> strings, which is mostly true but isn't true in the case of `aset`.
> > The same is true about concat, btw.
>
> I think it's less severe (`aset` can end up changing (by side-effect)
> a unibyte string to multibyte, i.e. changing the nature of the object,
> which I believe is the only time we do something like that), but yes
> similar problems appear elsewhere (hence the "mostly" above).
I'm not sure the "by side effect" part is an important distinction for
users, they might be surprised anyway. For example:
(let ((s1 "abcd")
(s2 "абвг"))
(message "s1: %s concat: %s"
(multibyte-string-p s1)
(multibyte-string-p (concat s1 s2))))
=> s1: nil concat: t
Some will say that this "converts" a unibyte string s1 to a multibyte
one just because it was concatenated.
People should always keep these gotchas in mind when working with
strings.
next prev parent reply other threads:[~2018-12-10 5:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-09 15:16 Why does using aset sometimes output raw bytes? Stephen Berman
2018-12-09 15:20 ` Eli Zaretskii
2018-12-09 15:46 ` Stephen Berman
2018-12-09 15:56 ` Stephen Berman
2018-12-09 17:12 ` Eli Zaretskii
2018-12-09 17:32 ` Stephen Berman
2018-12-09 17:47 ` Eli Zaretskii
2018-12-09 18:50 ` Stephen Berman
2018-12-09 18:55 ` Eli Zaretskii
2018-12-09 17:10 ` Stefan Monnier
2018-12-09 17:20 ` Stephen Berman
2018-12-09 19:20 ` Stefan Monnier
2018-12-09 20:23 ` Eli Zaretskii
2018-12-09 21:20 ` Stefan Monnier
2018-12-10 5:59 ` Eli Zaretskii [this message]
2018-12-10 13:56 ` Stefan Monnier
2018-12-09 20:43 ` Stephen Berman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83in013orr.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).