GNU bug report logs - #34975
26.1.92; In backquote, the comma marker does not work with variable name started with dot

Previous Next

Package: emacs;

Reported by: Xu Chunyang <mail <at> xuchunyang.me>

Date: Sun, 24 Mar 2019 14:21:01 UTC

Severity: normal

Tags: patch

Merged with 19790

Found in version 26.1.92

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34975 in the body.
You can then email your comments to 34975 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Sun, 24 Mar 2019 14:21:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Xu Chunyang <mail <at> xuchunyang.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 24 Mar 2019 14:21:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Xu Chunyang <mail <at> xuchunyang.me>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Sun, 24 Mar 2019 22:19:56 +0800
For example,

(let ((.foo 42))
  (list .foo))
;; => (42)

(let ((.foo 42))
  `(,.foo))
;; => ((\,\. foo))

I expect both of them returns (42). is it a bug?

The bug report is inspired by https://www.reddit.com/r/emacs/comments/b325ae/letplist_a_version_of_the_useful_letalist_macro/




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Sun, 24 Mar 2019 15:17:02 GMT) Full text and rfc822 format available.

Message #8 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Xu Chunyang <mail <at> xuchunyang.me>
Cc: 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Sun, 24 Mar 2019 16:16:02 +0100
Xu Chunyang <mail <at> xuchunyang.me> writes:

> For example,
>
> (let ((.foo 42))
>   (list .foo))
> ;; => (42)
>
> (let ((.foo 42))
>   `(,.foo))
> ;; => ((\,\. foo))
>
> I expect both of them returns (42). is it a bug?

AFAIU ,. is a reader macro:

(car (read ",.foo"))

  ==> \,\.

I dunno or have forgotten for what it had been intended, there are no
real uses in the Emacs Elisp sources.

> (let ((.foo 42))
>   `(,.foo))

You would have to write it differently, e.g.

(let ((.foo 42))
  `((\, .foo)))

  ==> (42)


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Mon, 25 Mar 2019 00:07:02 GMT) Full text and rfc822 format available.

Message #11 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Michael Heerdegen <michael_heerdegen <at> web.de>, Xu Chunyang
 <mail <at> xuchunyang.me>
Cc: 34975 <at> debbugs.gnu.org
Subject: RE: bug#34975: 26.1.92; In backquote, the comma marker does not work
 with variable name started with dot
Date: Sun, 24 Mar 2019 17:06:04 -0700 (PDT)
> AFAIU ,. is a reader macro: (car (read ",.foo"))
>   ==> \,\.
> 
> I dunno or have forgotten for what it had been intended, there are no
> real uses in the Emacs Elisp sources.
> 
> > (let ((.foo 42)) `(,.foo))

Yes, it's intended.  It acts the same as ,@

I might use it instead of ,@ to convey (to a human)
a connotation that what follows is not a proper list
(or is not necessarily a proper list), whereas ,@ is
typically thought of as splicing in a list of elements.

(I don't in fact use it, apparently, but I thought I
might have, and if I did use it instead of ,@ then it
would no doubt be for that reason.)

On the other hand, Common Lisp says that ,. has this
difference in meaning from ,@:

"Anywhere ``,@'' may be used, the syntax ``,.'' may
be used instead to indicate that it is permissible
to destroy the list produced by the form following
the ``,.''; this may permit more efficient code,
using nconc instead of append, for example."

https://www.cs.cmu.edu/Groups/AI/util/html/cltl/clm/node190.html#BACKQUOTE
 
> You would have to write it differently, e.g.
> 
> (let ((.foo 42)) `((\, .foo)))
>   ==> (42)

Yes.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Mon, 25 Mar 2019 01:35:01 GMT) Full text and rfc822 format available.

Message #14 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Mon, 25 Mar 2019 02:33:49 +0100
Drew Adams <drew.adams <at> oracle.com> writes:

> > I dunno or have forgotten for what it had been intended, there are no
> > real uses in the Emacs Elisp sources.
> >
> > > (let ((.foo 42)) `(,.foo))
>
> Yes, it's intended.  It acts the same as ,@
>
> I might use it instead of ,@ to convey (to a human)
> a connotation that what follows is not a proper list
> (or is not necessarily a proper list), whereas ,@ is
> typically thought of as splicing in a list of elements.
>
> (I don't in fact use it, apparently, but I thought I
> might have, and if I did use it instead of ,@ then it
> would no doubt be for that reason.)
>
> On the other hand, Common Lisp says that ,. has this
> difference in meaning from ,@:
>
> "Anywhere ``,@'' may be used, the syntax ``,.'' may
> be used instead to indicate that it is permissible
> to destroy the list produced by the form following
> the ``,.''; this may permit more efficient code,
> using nconc instead of append, for example."

Yes, thanks.  I also found that post:

https://lists.gnu.org/archive/html/emacs-devel/2012-02/msg00330.html

The state is the same as back then: ,. is a reader macro in Emacs Lisp,
but the head of the expansion (the symbol named ",.") doesn't have any
semantics, even not in backquote.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Mon, 25 Mar 2019 14:22:02 GMT) Full text and rfc822 format available.

Message #17 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
Subject: RE: bug#34975: 26.1.92; In backquote, the comma marker does not work
 with variable name started with dot
Date: Mon, 25 Mar 2019 07:21:11 -0700 (PDT)
> Yes, thanks.  I also found that post:
> 
> https://urldefense.proofpoint.com/v2/url?u=https-
> 3A__lists.gnu.org_archive_html_emacs-2Ddevel_2012-
> 2D02_msg00330.html&d=DwIFAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=k
> I3P6ljGv6CTHIKju0jqInF6AOwMCYRDQUmqX22rJ98&m=CxM0DPMvIA0IaOjx7pLPUAWhhKla65XR
> UOtlWoUp1pM&s=3ooHHbORUe59GfFU53KZE6gD6KNQLvxSeAKZuHs8TT8&e=
> 
> The state is the same as back then: ,. is a reader macro in Emacs Lisp,
> but the head of the expansion (the symbol named ",.") doesn't have any
> semantics, even not in backquote.

You're right; I was wrong.  I thought it did what
,@ does (which it should, whether or not it has the
extra difference of behavior specified for CL).

What it does in Emacs Lisp is _completely_ wrong, IMO.

(setq c 42)         ; c = 42
(setq a `(b ,. c))  ; a = (b (\,\. c))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Tue, 26 Mar 2019 00:05:01 GMT) Full text and rfc822 format available.

Message #20 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Tue, 26 Mar 2019 01:03:54 +0100
Drew Adams <drew.adams <at> oracle.com> writes:

> What it does in Emacs Lisp is _completely_ wrong, IMO.
>
> (setq c 42)         ; c = 42
> (setq a `(b ,. c))  ; a = (b (\,\. c))

Well, apart from the reader macro part, is has just never been
implemented.

I would already be happier if the current semantics of backquote would
be specified clearer in the docs: What happens with unquoted lists?
E.g.

(macroexpand '`(1 ,@x 3 ,@y))

 ==>
 (cons 1
      (append x
              '(3)
              y))

X is copied when evalling that, so the list stored in X is not modified
(good).  OTOH Y is not copied.  It's not necessary to copy the list
stored in Y to compute the value of the backquote expression without
modifying Y, so that's also ok.

But if you destructively modify the result of the backquote expression,
you may also change Y destructively (but not X).  Things like these
might be clear if you come from Common Lisp, but it's all not obvious
IMHO.


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Tue, 26 Mar 2019 09:50:01 GMT) Full text and rfc822 format available.

Message #23 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> suse.de>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, Drew Adams <drew.adams <at> oracle.com>,
 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Tue, 26 Mar 2019 10:49:14 +0100
On Mär 26 2019, Michael Heerdegen <michael_heerdegen <at> web.de> wrote:

> But if you destructively modify the result of the backquote expression,
> you may also change Y destructively (but not X).  Things like these
> might be clear if you come from Common Lisp, but it's all not obvious
> IMHO.

You need always be careful when destructively modifying structures,
independent of how they were computed.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab <at> suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Wed, 27 Mar 2019 01:51:01 GMT) Full text and rfc822 format available.

Message #26 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Andreas Schwab <schwab <at> suse.de>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Wed, 27 Mar 2019 02:50:14 +0100
Andreas Schwab <schwab <at> suse.de> writes:

> On Mär 26 2019, Michael Heerdegen <michael_heerdegen <at> web.de> wrote:
>
> > But if you destructively modify the result of the backquote expression,
> > you may also change Y destructively (but not X).  Things like these
> > might be clear if you come from Common Lisp, but it's all not obvious
> > IMHO.
>
> You need always be careful when destructively modifying structures,
> independent of how they were computed.

What I wanted to say was that it can be surprising that splicing may
reuse conses at all (it had been to me).  The manual only tells that the
elements of the spliced list "become elements of the result".  I had to
learn it the hard way.  I had been careful, but I just didn't expect a
problem in that situation.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Thu, 04 Apr 2019 03:32:02 GMT) Full text and rfc822 format available.

Message #29 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, Drew Adams <drew.adams <at> oracle.com>,
 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Wed, 03 Apr 2019 23:31:24 -0400
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Drew Adams <drew.adams <at> oracle.com> writes:
>
>> > I dunno or have forgotten for what it had been intended, there are no
>> > real uses in the Emacs Elisp sources.
>> >

>> (I don't in fact use it, apparently, but I thought I
>> might have, and if I did use it instead of ,@ then it
>> would no doubt be for that reason.)
>>
>> On the other hand, Common Lisp says that ,. has this
>> difference in meaning from ,@:
>>
>> "Anywhere ``,@'' may be used, the syntax ``,.'' may
>> be used instead to indicate that it is permissible
>> to destroy the list produced by the form following
>> the ``,.''; this may permit more efficient code,
>> using nconc instead of append, for example."
>
> Yes, thanks.  I also found that post:
>
> https://lists.gnu.org/archive/html/emacs-devel/2012-02/msg00330.html
>
> The state is the same as back then: ,. is a reader macro in Emacs Lisp,
> but the head of the expansion (the symbol named ",.") doesn't have any
> semantics, even not in backquote.

There's also Bug#19790 about this.  I think it makes sense to just
remove this reader macro, as far as I can tell, nobody really wants this
destructive splicing feature.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Thu, 04 Apr 2019 13:11:02 GMT) Full text and rfc822 format available.

Message #32 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: michael_heerdegen <at> web.de, mail <at> xuchunyang.me, 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Thu, 04 Apr 2019 16:10:19 +0300
> From: Noam Postavsky <npostavs <at> gmail.com>
> Date: Wed, 03 Apr 2019 23:31:24 -0400
> Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
> 
> There's also Bug#19790 about this.  I think it makes sense to just
> remove this reader macro, as far as I can tell, nobody really wants this
> destructive splicing feature.

How hard would it be fixing it?  I'm uneasy with removing features
because we are confused about them.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Thu, 04 Apr 2019 13:26:02 GMT) Full text and rfc822 format available.

Message #35 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: michael_heerdegen <at> web.de, mail <at> xuchunyang.me, 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Thu, 04 Apr 2019 09:25:48 -0400
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Noam Postavsky <npostavs <at> gmail.com>
>> Date: Wed, 03 Apr 2019 23:31:24 -0400
>> Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
>> 
>> There's also Bug#19790 about this.  I think it makes sense to just
>> remove this reader macro, as far as I can tell, nobody really wants this
>> destructive splicing feature.
>
> How hard would it be fixing it?  I'm uneasy with removing features
> because we are confused about them.

The destructive splicing feature was never added though.  Only the
reader macro part.  But if you're asking about possible breakage, then
yes, it's possible that someone out there wrote a macro which gives some
semantics to ",.", like pcase gives its own semantics to "`" and ",".





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Thu, 04 Apr 2019 22:30:02 GMT) Full text and rfc822 format available.

Message #38 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: michael_heerdegen <at> web.de, Eli Zaretskii <eliz <at> gnu.org>, mail <at> xuchunyang.me,
 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Thu, 04 Apr 2019 23:28:55 +0100
Noam Postavsky <npostavs <at> gmail.com> writes:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> From: Noam Postavsky <npostavs <at> gmail.com>
>>> Date: Wed, 03 Apr 2019 23:31:24 -0400
>>> Cc: Xu Chunyang <mail <at> xuchunyang.me>, 34975 <at> debbugs.gnu.org
>>> 
>>> There's also Bug#19790 about this.  I think it makes sense to just
>>> remove this reader macro, as far as I can tell, nobody really wants this
>>> destructive splicing feature.
>>
>> How hard would it be fixing it?  I'm uneasy with removing features
>> because we are confused about them.
>
> The destructive splicing feature was never added though.  Only the
> reader macro part.  But if you're asking about possible breakage, then
> yes, it's possible that someone out there wrote a macro which gives some
> semantics to ",.", like pcase gives its own semantics to "`" and ",".

I, for one, have several times found myself using nconc+list where I
would rather use backquote, precisely because the latter is never
destructive.

Not a must-have by any measure, but definitely a nice-to-have,
especially given the reader macro already exists.

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Thu, 04 Apr 2019 23:38:02 GMT) Full text and rfc822 format available.

Message #41 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: michael_heerdegen <at> web.de, Eli Zaretskii <eliz <at> gnu.org>, mail <at> xuchunyang.me,
 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Thu, 04 Apr 2019 19:37:50 -0400
>>>> as far as I can tell, nobody really wants this
>>>> destructive splicing feature.

> I, for one, have several times found myself using nconc+list where I
> would rather use backquote, precisely because the latter is never
> destructive.

Okay, I stand corrected.  But to be honest, that sounds like premature
optimization to me.  By the way, in Bug#19790 Stefan opposed making ",."
destructive.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19790#23





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Fri, 05 Apr 2019 01:16:02 GMT) Full text and rfc822 format available.

Message #44 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: michael_heerdegen <at> web.de, Eli Zaretskii <eliz <at> gnu.org>, mail <at> xuchunyang.me,
 34975 <at> debbugs.gnu.org
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Fri, 05 Apr 2019 02:15:18 +0100
Noam Postavsky <npostavs <at> gmail.com> writes:

>>>>> as far as I can tell, nobody really wants this
>>>>> destructive splicing feature.
>
>> I, for one, have several times found myself using nconc+list where I
>> would rather use backquote, precisely because the latter is never
>> destructive.
>
> Okay, I stand corrected.  But to be honest, that sounds like premature
> optimization to me.

That or dubious style, indeed. ;)

> By the way, in Bug#19790 Stefan opposed making ",."  destructive.
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19790#23

My knee-jerk reaction is simply "if it's already there, why not realise
its purpose", but I ultimately don't mind either way.

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34975; Package emacs. (Fri, 05 Apr 2019 06:23:01 GMT) Full text and rfc822 format available.

Message #47 received at 34975 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: michael_heerdegen <at> web.de, 34975 <at> debbugs.gnu.org, npostavs <at> gmail.com,
 mail <at> xuchunyang.me
Subject: Re: bug#34975: 26.1.92;
 In backquote, the comma marker does not work with variable name
 started with dot
Date: Fri, 05 Apr 2019 09:21:47 +0300
> From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
> Cc: michael_heerdegen <at> web.de,  Eli Zaretskii <eliz <at> gnu.org>,  mail <at> xuchunyang.me,  34975 <at> debbugs.gnu.org
> Date: Fri, 05 Apr 2019 02:15:18 +0100
> 
> My knee-jerk reaction is simply "if it's already there, why not realise
> its purpose", but I ultimately don't mind either way.

Same here.




Merged 19790 34975. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 10 Apr 2019 00:32:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 25 Oct 2019 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 185 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.