all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* nested backquotes
@ 2003-09-24 14:03 Carlos Ungil
  2003-09-24 14:22 ` Carlos Ungil
  0 siblings, 1 reply; 12+ messages in thread
From: Carlos Ungil @ 2003-09-24 14:03 UTC (permalink / raw)


Hello,

I've found (what I think it is) a bug when using nested backquotes.

What follows has been executed using "emacs --no-init".
I understand that the first test is giving the right result, and that 
in the other cases there is a problem with the backquotes.

Maybe the reason it works in windows is because I'm 
using a more recent version (21.3.50, compared to 21.2.1 in linux 
and solaris), and the bug has indeed been fixed already, but I've 
found no references to this bug in emacs newsgroups, or in the 
PROBLEMS file (and the file backquote.el has not been changed, but 
maybe the origin of the bug was somewhere else).

Regards,

Carlos Ungil

-----

(emacs-version)
=>"GNU Emacs 21.3.50.1 (i386-mingw-nt5.1.2600) of 2003-08-21 on MIDASPSE17"

(defmacro test ()
  ``(a ,b ,,c))
=>test

(let ((a 1) (b 2) (c 3))
  (macroexpand (macroexpand '(test))))
=>(list (quote a) b 3)

-----

(emacs-version)
=>"GNU Emacs 21.2.1 (sparc-sun-solaris2.9, X toolkit, Xaw3d scroll bars) of 2003-05-19 on watford-71"

(defmacro test ()
  ``(a ,b ,,c))
=>test

(let ((a 1) (b 2) (c 3))
  (macroexpand (macroexpand '(test))))
=>(list (quote a) b \,c)

-----

(emacs-version)
=>"GNU Emacs 21.2.1 (i386-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2002-04-09 on porky.devel.redhat.com"

(defmacro test ()
  ``(a ,b ,,c))
=>test

(let ((a 1) (b 2) (c 3))
  (macroexpand (macroexpand '(test))))
=>(list (quote a) b \,c)

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

* Re: nested backquotes
  2003-09-24 14:03 nested backquotes Carlos Ungil
@ 2003-09-24 14:22 ` Carlos Ungil
  0 siblings, 0 replies; 12+ messages in thread
From: Carlos Ungil @ 2003-09-24 14:22 UTC (permalink / raw)


Hello,

in fact the problem was not in the backquotes but in the commas.
Using
           ``(a ,b ,(, c))
instead of 	
           ``(a ,b ,,c)
works fine.

Cheers,

Carlos Ungil

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

* nested backquotes
@ 2005-05-18 15:13 Matthieu Moy
  2005-05-18 15:50 ` rgb
  0 siblings, 1 reply; 12+ 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] 12+ messages in thread

* Re: nested backquotes
  2005-05-18 15:13 Matthieu Moy
@ 2005-05-18 15:50 ` rgb
  2005-05-18 16:19   ` Matthieu Moy
  0 siblings, 1 reply; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ 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; 12+ 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] 12+ messages in thread

* Re: nested backquotes
  2005-05-21  9:51           ` Matthieu Moy
@ 2005-05-21 10:02             ` Matthieu Moy
  0 siblings, 0 replies; 12+ 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] 12+ messages in thread

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

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-24 14:03 nested backquotes Carlos Ungil
2003-09-24 14:22 ` Carlos Ungil
  -- strict thread matches above, loose matches on Subject: below --
2005-05-18 15:13 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.