unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* nested backquotes
@ 2005-05-18 15:13 Matthieu Moy
  2005-05-18 15:50 ` rgb
  0 siblings, 1 reply; 10+ messages in thread
From: Matthieu Moy @ 2005-05-18 15:13 UTC (permalink / raw)


Hi,

I'm experiencing problems with nested backquotes in Emacs lisp:

Emacs 21 says:

ELISP> ``( ,,(+ 1 2))
(cons
 (+ 1 2))

Whereas XEmacs says:
ELISP> ``( ,,(+ 1 2))
(list 3)

Question 1: Who is right? (I'd say XEmacs here. I don't understand
Emacs's behavior)

Question 2: Is there a portable way to use nested backquotes in Emacs
Lisp?

Thanks,

-- 
Matthieu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-18 15:13 nested backquotes Matthieu Moy
@ 2005-05-18 15:50 ` rgb
  2005-05-18 16:19   ` Matthieu Moy
  0 siblings, 1 reply; 10+ messages in thread
From: rgb @ 2005-05-18 15:50 UTC (permalink / raw)


> I'm experiencing problems with nested backquotes in Emacs lisp:
>
> Emacs 21 says:
>
> ELISP> ``( ,,(+ 1 2))
> (cons
>  (+ 1 2))

On 22.0.50 I'm getting (list 3)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-18 15:50 ` rgb
@ 2005-05-18 16:19   ` Matthieu Moy
  2005-05-18 18:21     ` Thierry Emery
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Matthieu Moy @ 2005-05-18 16:19 UTC (permalink / raw)


"rgb" <rbielaws@i1.net> writes:

>> I'm experiencing problems with nested backquotes in Emacs lisp:
>>
>> Emacs 21 says:
>>
>> ELISP> ``( ,,(+ 1 2))
>> (cons
>>  (+ 1 2))
>
> On 22.0.50 I'm getting (list 3)

Surprisingly, backquote.el hasn't changed much. Loading backquote.el
from CVS on my Emacs 21 "works" (in the sense that it doesn't break my
Emacs), but still gets the same result.

So, I'm still looking for a portable solution ... :-(

The goal would be to implement this:

  https://mail.gna.org/public/xtla-el-dev/2004-11/msg00078.html

Or the variant

  https://mail.gna.org/public/xtla-el-dev/2004-12/msg00001.html

in Xtla, without droping support for GNU Emacs 22.

-- 
Matthieu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-18 16:19   ` Matthieu Moy
@ 2005-05-18 18:21     ` Thierry Emery
  2005-05-20 15:16     ` Stefan Monnier
  2005-05-20 15:24     ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Thierry Emery @ 2005-05-18 18:21 UTC (permalink / raw)


Hi,

Matthieu Moy <MatthieuNOSPAM.Moy@imag.fr.invalid> writes:

> "rgb" <rbielaws@i1.net> writes:
>
>> > I'm experiencing problems with nested backquotes in Emacs lisp:
>> > 
>> > Emacs 21 says:
>> > 
>> > ELISP> ``( ,,(+ 1 2))
>> > (cons
>> >  (+ 1 2))
>> 
>> On 22.0.50 I'm getting (list 3)
>
> Surprisingly, backquote.el hasn't changed much. Loading backquote.el
> from CVS on my Emacs 21 "works" (in the sense that it doesn't break my
> Emacs), but still gets the same result.
>
> So, I'm still looking for a portable solution ... :-(

(` (` ( (, (, (+ 1 2))))))

tested on GNU Emacs 21.4 and 22.0.50, and on XEmacs 21.4.17,
consistently returns :
(list 3)

Hoping this helps,

Thierry
-- 
thierry |dot| emery |at| free |dot| fr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-18 16:19   ` Matthieu Moy
  2005-05-18 18:21     ` Thierry Emery
@ 2005-05-20 15:16     ` Stefan Monnier
  2005-05-20 15:24     ` Stefan Monnier
  2 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2005-05-20 15:16 UTC (permalink / raw)


>> On 22.0.50 I'm getting (list 3)

> Surprisingly, backquote.el hasn't changed much. Loading backquote.el

The bug fixed in Emacs-CVS was in the Lisp reader that handles the backquote
syntax, not the backquote expansion.


        Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-18 16:19   ` Matthieu Moy
  2005-05-18 18:21     ` Thierry Emery
  2005-05-20 15:16     ` Stefan Monnier
@ 2005-05-20 15:24     ` Stefan Monnier
  2005-05-20 16:05       ` Matthieu Moy
  2 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2005-05-20 15:24 UTC (permalink / raw)


> The goal would be to implement this:
>   https://mail.gna.org/public/xtla-el-dev/2004-11/msg00078.html
> Or the variant
>   https://mail.gna.org/public/xtla-el-dev/2004-12/msg00001.html
> in Xtla, without droping support for GNU Emacs 22.

Maybe I'm way off-base, but lexical-let sounds like a better alternative.
When capturing things like the current buffer, you can just replace

     `(lambda (...) ... ,(current-buffer) ...)
with
     (lexical-let ((buf (current-buffer)))
       (lambda (...) ... buf ...))


-- Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-20 15:24     ` Stefan Monnier
@ 2005-05-20 16:05       ` Matthieu Moy
  2005-05-20 20:25         ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Matthieu Moy @ 2005-05-20 16:05 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Maybe I'm way off-base, but lexical-let sounds like a better alternative.
> When capturing things like the current buffer, you can just replace
>
>      `(lambda (...) ... ,(current-buffer) ...)
> with
>      (lexical-let ((buf (current-buffer)))
>        (lambda (...) ... buf ...))

With the "capture" version, you can also do

(tla--lambda-with-capture (x y z)
  (... foo ... (capture foo) ... (capture (current-buffer))))

which I find more readable. (I've started to look at the lexical-let
option too)

Thanks for your help anyway.

-- 
Matthieu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-20 16:05       ` Matthieu Moy
@ 2005-05-20 20:25         ` Stefan Monnier
  2005-05-21  9:51           ` Matthieu Moy
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2005-05-20 20:25 UTC (permalink / raw)


> With the "capture" version, you can also do

> (tla--lambda-with-capture (x y z)
>   (... foo ... (capture foo) ... (capture (current-buffer))))

Could you explain what this does?

> which I find more readable. (I've started to look at the lexical-let
> option too)

The advantage of lexical-let is that it uses a completely standard concept
(lexical scoping and closures) which exists in many other languages (where
their `let' behaves pretty much like Emacs's lexical-let).


        Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-20 20:25         ` Stefan Monnier
@ 2005-05-21  9:51           ` Matthieu Moy
  2005-05-21 10:02             ` Matthieu Moy
  0 siblings, 1 reply; 10+ messages in thread
From: Matthieu Moy @ 2005-05-21  9:51 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> With the "capture" version, you can also do
>
>> (tla--lambda-with-capture (x y z)
>>   (... foo ... (capture foo) ... (capture (current-buffer))))
>
> Could you explain what this does?

It expands to something like

`(lambda (x y z)
   (let ((tla1 foo)
         (tla2 (current-buffer)))
     (funcall (lambda () (... foo ... tla1 ... tla2)))))

So, we still have the backquoted lambda, but containing only a let and
a funcall, the actual body being byte-compiled.

The translation from our backquote + comma version is roughly

s/`(lambda/(tla--lambda-with-capture/g
s/,.*/(capture \1)/

-- 
Matthieu

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: nested backquotes
  2005-05-21  9:51           ` Matthieu Moy
@ 2005-05-21 10:02             ` Matthieu Moy
  0 siblings, 0 replies; 10+ messages in thread
From: Matthieu Moy @ 2005-05-21 10:02 UTC (permalink / raw)


Matthieu Moy <MatthieuNOSPAM.Moy@imag.fr.invalid> writes:

> `(lambda (x y z)
>    (let ((tla1 ,foo)
                 ^
>          (tla2 ,(current-buffer)))
                 ^
>      (funcall (lambda () (... foo ... tla1 ... tla2)))))

I had forgotten the commas, sorry.

-- 
Matthieu

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-05-21 10:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-18 15:13 nested backquotes Matthieu Moy
2005-05-18 15:50 ` rgb
2005-05-18 16:19   ` Matthieu Moy
2005-05-18 18:21     ` Thierry Emery
2005-05-20 15:16     ` Stefan Monnier
2005-05-20 15:24     ` Stefan Monnier
2005-05-20 16:05       ` Matthieu Moy
2005-05-20 20:25         ` Stefan Monnier
2005-05-21  9:51           ` Matthieu Moy
2005-05-21 10:02             ` Matthieu Moy

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).