From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: emacs-devel@gnu.org
Subject: Re: Lexical let and setq
Date: Sat, 14 Sep 2013 16:04:44 +0200 [thread overview]
Message-ID: <878uyza48z.fsf@informatimago.com> (raw)
In-Reply-To: m3fvt71wrn.fsf@stories.gnus.org
Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> That one is OK, since recursion is not supported efficiently.
>> The problem is when people use the above because they're writing (poor)
>> C code in Elisp (e.g. they begin their functions with a big let
>> declaring all the local vars that they may use later on in the
>> function).
>
> I think the most common reason for stashing a lot of variables in a let
> is to avoid infinite indentation.
>
> (let ((a (foo)))
> (something)
> (let ((b (something-else)))
> (more a b)
> (let ((c (yet-more)))
> (zot a b c))))
>
> vs
>
> (let ((a (foo))
> b c)
> (something)
> (setq b (something-else))
> (more a b)
> (setq c (yet-more))
> (zot a b c))
>
> I kinda think the latter form is sometimes more readable.
Err, no. A form with less indentation MAY be more readable, but not
when it's a procedural form with a setq every other subform.
If something similar and systematicall occurs from one level of
indentation to the other, then you can write a macro that will do this
uniform something, and have a unindented body:
(something-similar
(foo)
(something)
(something-else)
(more)
(yet-more)
(zot))
A simple example would be:
(defmacro pipe (input &rest functions)
(pipe-aux input functions))
(defun pipe-aux (input functions)
(if functions
(pipe-aux (list (first functions) input)
(rest functions))
input))
(macroexpand '(pipe foo a b c d e f g)) ; --> (g (f (e (d (c (b (a foo)))))))
So you just write
(pipe foo
a
b
c
d
e
f
g)
or rather:
(pipe foo a b c d e f g)
But in case of your let, it is much harder to read, because now you must
rebuild the data flow from the variables and setq expressions. The
indented form was much clearer, because you can more easily skip a
subexpression, knowing for sure that whatever happens to variables in
subexpressions can't affect the rest.
--
__Pascal Bourguignon__
http://www.informatimago.com/
next prev parent reply other threads:[~2013-09-14 14:04 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-06 20:59 bug#15294: 24.3.50; js2-mode parser is several times slower in lexical-binding mode Dmitry Gutov
2013-09-06 23:44 ` Xue Fuqiao
2013-09-07 3:15 ` Stefan Monnier
2013-09-08 22:32 ` Stefan Monnier
2013-09-10 2:04 ` Stefan Monnier
2013-09-13 3:40 ` Stefan Monnier
2013-09-13 3:59 ` Drew Adams
2013-09-13 4:37 ` Stefan Monnier
2013-09-13 5:45 ` Drew Adams
2013-09-13 13:01 ` Stefan Monnier
2013-09-14 0:09 ` Lexical let and setq Michael Welsh Duggan
2013-09-14 3:46 ` Stefan Monnier
2013-09-14 11:13 ` Lars Magne Ingebrigtsen
2013-09-14 14:04 ` Pascal J. Bourguignon [this message]
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-14 4:20 ` bug#15294: 24.3.50; js2-mode parser is several times slower in lexical-binding mode Dmitry Gutov
2013-09-14 14:27 ` Stefan Monnier
2013-09-15 0:11 ` Dmitry Gutov
2013-09-15 5:04 ` Stefan Monnier
2013-09-15 16:54 ` Richard Stallman
2013-09-15 0:24 ` Dmitry Gutov
2013-09-15 5:06 ` Stefan Monnier
2013-09-18 23:48 ` Stefan Monnier
2013-09-22 4:56 ` Dmitry Gutov
2013-10-03 5:00 ` Stefan Monnier
2013-10-04 2:38 ` Dmitry Gutov
2013-10-04 13:52 ` Stefan Monnier
2013-10-05 3:27 ` Dmitry Gutov
2014-12-14 12:31 ` Dmitry Gutov
2014-12-14 14:08 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2013-09-16 15:59 Lexical let and setq 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878uyza48z.fsf@informatimago.com \
--to=pjb@informatimago.com \
--cc=emacs-devel@gnu.org \
/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 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.