unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Implement letrec without backquote?
@ 2016-11-04 17:39 Tino Calancha
  2016-11-05  8:26 ` John Wiegley
  0 siblings, 1 reply; 8+ messages in thread
From: Tino Calancha @ 2016-11-04 17:39 UTC (permalink / raw)
  To: emacs-devel; +Cc: tino.calancha


Hi,

i am sorry if this question results naive.
Is there any advantage on this patch?

*) I don't see significant differences neither in performance
   nor readability: in the patch, the macro expands to just
   one setq call.  Initially, i thought this could be an advantage,
   but after running some checks i don't see differences.

*) This patch doesn't use backquote, but as longer as `letrec' is
   not used in an early stage of the bootstrap this doesn't matter.

Thank you.
Tino

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From e11cb762efa4ab7e6ea9bdc755d95d4275c6b715 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Sat, 5 Nov 2016 02:12:28 +0900
Subject: [PATCH] * lisp/subr.el (letrec):  Reimplement it without backquote

---
 lisp/subr.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index fba43be..e667e85 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1529,9 +1529,9 @@ letrec
   ;; As a special-form, we could implement it more efficiently (and cleanly,
   ;; making the vars actually unbound during evaluation of the binders).
   (declare (debug let) (indent 1))
-  `(let ,(mapcar #'car binders)
-     ,@(mapcar (lambda (binder) `(setq ,@binder)) binders)
-     ,@body))
+  (nconc (list 'let (mapcar #'car binders)
+               (apply #'append (cons '(setq) binders)))
+         body))
 
 (defmacro with-wrapper-hook (hook args &rest body)
   "Run BODY, using wrapper functions from HOOK with additional ARGS.
-- 
2.10.1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.2)
 of 2016-11-03 built on calancha-pc
Repository revision: abe594c0990a4e6bc72b20b7ff06b4b0c01a682c




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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-04 17:39 [PATCH] Implement letrec without backquote? Tino Calancha
@ 2016-11-05  8:26 ` John Wiegley
  2016-11-05  8:43   ` Tino Calancha
  0 siblings, 1 reply; 8+ messages in thread
From: John Wiegley @ 2016-11-05  8:26 UTC (permalink / raw)
  To: Tino Calancha; +Cc: emacs-devel

>>>>> "TC" == Tino Calancha <tino.calancha@gmail.com> writes:

TC> i am sorry if this question results naive. Is there any advantage on this
TC> patch?

I prefer the backquoted version.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05  8:26 ` John Wiegley
@ 2016-11-05  8:43   ` Tino Calancha
  2016-11-05  8:48     ` John Wiegley
  0 siblings, 1 reply; 8+ messages in thread
From: Tino Calancha @ 2016-11-05  8:43 UTC (permalink / raw)
  To: John Wiegley; +Cc: Tino Calancha, Emacs developers



On Sat, 5 Nov 2016, John Wiegley wrote:

>>>>>> "TC" == Tino Calancha <tino.calancha@gmail.com> writes:
>
> TC> i am sorry if this question results naive. Is there any advantage on this
> TC> patch?
>
> I prefer the backquoted version.
Thanks John for your answer.
Just for my own education because i am not expert as you, let me ask you,
Why do you prefer the original one?
Maybe is it more readable?



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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05  8:43   ` Tino Calancha
@ 2016-11-05  8:48     ` John Wiegley
  2016-11-05  9:05       ` Tino Calancha
  0 siblings, 1 reply; 8+ messages in thread
From: John Wiegley @ 2016-11-05  8:48 UTC (permalink / raw)
  To: Tino Calancha; +Cc: Emacs developers

>>>>> Tino Calancha <tino.calancha@gmail.com> writes:

> Just for my own education because i am not expert as you, let me ask you,
> Why do you prefer the original one? Maybe is it more readable?

That's a good question. I think it's because I've written far more macros
using the former style than the latter, so it reads more naturally to me.
The "list construction" style is also valid, but has always felt more
awkward. That said, others might feel exactly the opposite.

But in the absence of a definitive style guide, I'd say: stick with what
we have already.

Thanks for the taking the time to submit a patch!

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05  8:48     ` John Wiegley
@ 2016-11-05  9:05       ` Tino Calancha
  2016-11-05 10:21         ` Andreas Schwab
  2016-11-05 17:59         ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: Tino Calancha @ 2016-11-05  9:05 UTC (permalink / raw)
  To: John Wiegley; +Cc: Tino Calancha, Emacs developers



On Sat, 5 Nov 2016, John Wiegley wrote:

>>>>>> Tino Calancha <tino.calancha@gmail.com> writes:
>
>> Just for my own education because i am not expert as you, let me ask you,
>> Why do you prefer the original one? Maybe is it more readable?
>
> That's a good question. I think it's because I've written far more macros
> using the former style than the latter, so it reads more naturally to me.
> The "list construction" style is also valid, but has always felt more
> awkward. That said, others might feel exactly the opposite.
I see.  Thank you for the explanation.  The backquote is very intuitive, i
think more suitable for humans.
My motivation to write that was after reading several old comments in
subr.el like 'do not use backquote here, it's too early'.

Also, i wanted to expand in just one setq call, that is, instead of
(setq x 1) (setq y 2) ... (setq foo N)
like this:
(setq x 1 y 2 ... foo N)

But, it seems it's doesn't bring a better efficiency.

> But in the absence of a definitive style guide, I'd say: stick with what
> we have already.
Fair enough.  It's important to keep code style consistency.

> Thanks for the taking the time to submit a patch!
Thanks to you for your answer!



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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05  9:05       ` Tino Calancha
@ 2016-11-05 10:21         ` Andreas Schwab
  2016-11-05 11:24           ` Tino Calancha
  2016-11-05 17:59         ` Stefan Monnier
  1 sibling, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2016-11-05 10:21 UTC (permalink / raw)
  To: Tino Calancha; +Cc: John Wiegley, Emacs developers

On Nov 05 2016, Tino Calancha <tino.calancha@gmail.com> wrote:

> Also, i wanted to expand in just one setq call, that is, instead of
> (setq x 1) (setq y 2) ... (setq foo N)
> like this:
> (setq x 1 y 2 ... foo N)
>
> But, it seems it's doesn't bring a better efficiency.

That's because setq is a bytecode primitive, and both variants are
compiled to the same byte code.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05 10:21         ` Andreas Schwab
@ 2016-11-05 11:24           ` Tino Calancha
  0 siblings, 0 replies; 8+ messages in thread
From: Tino Calancha @ 2016-11-05 11:24 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: John Wiegley, Emacs developers, Tino Calancha



On Sat, 5 Nov 2016, Andreas Schwab wrote:

> On Nov 05 2016, Tino Calancha <tino.calancha@gmail.com> wrote:
>
>> Also, i wanted to expand in just one setq call, that is, instead of
>> (setq x 1) (setq y 2) ... (setq foo N)
>> like this:
>> (setq x 1 y 2 ... foo N)
>>
>> But, it seems it's doesn't bring a better efficiency.
>
> That's because setq is a bytecode primitive, and both variants are
> compiled to the same byte code.
>
> Andreas.

Thank you! I was quite puzzle with that behaviour.




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

* Re: [PATCH] Implement letrec without backquote?
  2016-11-05  9:05       ` Tino Calancha
  2016-11-05 10:21         ` Andreas Schwab
@ 2016-11-05 17:59         ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2016-11-05 17:59 UTC (permalink / raw)
  To: emacs-devel

> I see.  Thank you for the explanation.  The backquote is very intuitive, i
> think more suitable for humans.

It's also easier to replace the ` with edebug-` when you need it (and
ideally, edebug should be able to do that automatically).


        Stefan




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

end of thread, other threads:[~2016-11-05 17:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04 17:39 [PATCH] Implement letrec without backquote? Tino Calancha
2016-11-05  8:26 ` John Wiegley
2016-11-05  8:43   ` Tino Calancha
2016-11-05  8:48     ` John Wiegley
2016-11-05  9:05       ` Tino Calancha
2016-11-05 10:21         ` Andreas Schwab
2016-11-05 11:24           ` Tino Calancha
2016-11-05 17:59         ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

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