unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Welsh Duggan <mwd@md5i.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Lexical let and setq
Date: Fri, 13 Sep 2013 20:09:05 -0400	[thread overview]
Message-ID: <878uz0e02m.fsf_-_@maru2.md5i.com> (raw)
In-Reply-To: <jwvzjrhqrft.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 13 Sep 2013 00:37:25 -0400")

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

[...]

> I do hope to fix those issues by introducing other byte-codes which will
> let us generate significantly more efficient code for those constructs,
> but in 24.1, the priority was to get lexical-binding to work correctly,
> performance being a secondary concern (tho for most idiomatic Elisp
> code, the performance tends to be competitive).
>
> What people should know is that
>
>    (let (x y z)
>      ...(setq x ...)
>      ...(setq z ...)
>      ...(setq y ...)
>
> is often a bad idea in Elisp, and even more so in lexical-binding code
> (in some cases, if a variable is immutable it can be handled
> significantly more efficiently, so the mere existence of a single `setq'
> on a variable can sometimes slow other chunks of code: in many cases
> `let' is cheaper than `setq').

The primary reason I have seen the (let (foo) (setq foo ...)) idiom is
in looping code.  The way I would normally try to avoid this idiom in
most FP languages would be to use recursion (specifically tail
recursion, if possible).  I know some work was done on implementing
efficient tail-recursion in the byte compiler.  Has any of that made it
onto the trunk yet?

-- 
Michael Welsh Duggan
(md5i@md5i.com)



       reply	other threads:[~2013-09-14  0:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <871u51ll93.fsf@yandex.ru>
     [not found] ` <jwvzjrly386.fsf-monnier+emacs@gnu.org>
     [not found]   ` <jwvhadps8a1.fsf-monnier+emacs@gnu.org>
     [not found]     ` <0b29ebee-8ed4-47e2-816b-910a013a0898@default>
     [not found]       ` <jwvzjrhqrft.fsf-monnier+emacs@gnu.org>
2013-09-14  0:09         ` Michael Welsh Duggan [this message]
2013-09-14  3:46           ` Lexical let and setq Stefan Monnier
2013-09-14 11:13             ` Lars Magne Ingebrigtsen
2013-09-14 14:04               ` Pascal J. Bourguignon
2013-09-15  5:11               ` Stefan Monnier
2013-09-14 21:47           ` Richard Stallman
2013-09-15  5:09             ` Stefan Monnier
2013-09-15 16:54               ` Richard Stallman
2013-09-15 17:06                 ` Stefan Monnier
2013-09-16 10:47                   ` Richard Stallman
2013-09-16 15:59 Barry OReilly

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=878uz0e02m.fsf_-_@maru2.md5i.com \
    --to=mwd@md5i.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
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).