[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Real-life examples of lexical binding in Emacs Lisp
From: |
Emanuel Berg |
Subject: |
Re: Real-life examples of lexical binding in Emacs Lisp |
Date: |
Wed, 17 Jun 2015 22:22:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> independence from other functions, you would have
>> to PREFIX ALL THE LOCAL VARIABLES WITH FUNCTION
>> SPECIFIC PREFIXES!
>
> Actually, not really. The Elisp convention to only
> use prefixes for global variables is 99% sufficient.
> In your example, the problem is that `some-function'
> modifies the (presumably global) variable
> `scratch-buffer' and that this variable does not
> have an appropriate prefix.
I'm curious, the techno-science books always speak of
LISP as a language for "symbolic manipulation".
Sometimes they mention AI. Anyone care to explain
this? Does it somehow relate to the "dynamic scope"?
Or is an implementation-derived situation, i.e.
a practical measure somewhere along the way?
> The only case where non-prefixed local variables
> cause problem is when you introduce higher-order
> functions, as in:
>
> (defun my-map (f l) (if l (cons (funcall f (car l))
> (my-map f (cdr l)))))
>
> (defun my-function (input) (let ((l ...)) (my-map
> (lambda (x) (unless (memq x l) (error "invalid
> mapping"))) input)))
>
> Suddenly the `l' used inside the lambda will not
> refer to the `l' nearby but to the `l' argument of
> `my-map'. For this reason, some higher-order
> functions used to use weird argument names to try
> and avoid such name capture. Nowadays they can use
> lexical scoping and hence choose their variable
> names sanely and without fear.
And that is not only desired for that reason but also
for "1-order functions" (? - i.e., a plebeian function
with non-function arguments only) because then you can
just name your variables whatever comes to mind - be
it good or bad, you don't want to worry about the
world outside that cozy form. It is the blue collar
bottom up, contrary to the "top-down" (yuk!) hysteria
of white collar hackers...
I once read that "the programmer has the whole program
in his head" (pseudo-quote). That's not how
I experience it. I have some general knowledge of the
entire program for sure, but the only thing I have
100% in my head is the function or even code block I'm
currently typing. The dynamic scope breaks that zone
of comfort, which here, is where you want to be.
This "dynamic scope" as a method is like programming
on acid with the ant queen communicating to her
minions through telepathy telling them what to do all
the time. "Lexical scope" is layed-back, having the
ants do their work semi-autonomously, now and then
interfering to solve a well-defined and delimited
problem. ... Right?
--
underground experts united
http://user.it.uu.se/~embe8573
- Re: Real-life examples of lexical binding in Emacs Lisp, (continued)
- Re: Real-life examples of lexical binding in Emacs Lisp, Pascal J. Bourguignon, 2015/06/14
- Re: Real-life examples of lexical binding in Emacs Lisp, Jim Diamond, 2015/06/16
- Re: Real-life examples of lexical binding in Emacs Lisp, Emanuel Berg, 2015/06/16
- Re: Real-life examples of lexical binding in Emacs Lisp, Andreas Röhler, 2015/06/17
- Message not available
- Re: Real-life examples of lexical binding in Emacs Lisp, Pascal J. Bourguignon, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Pascal J. Bourguignon, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Stefan Monnier, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Andreas Röhler, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Tassilo Horn, 2015/06/17
- Message not available
- Re: Real-life examples of lexical binding in Emacs Lisp, Stefan Monnier, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp,
Emanuel Berg <=
- Re: Real-life examples of lexical binding in Emacs Lisp, Pascal J. Bourguignon, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Emanuel Berg, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Udyant Wig, 2015/06/18
- Re: Real-life examples of lexical binding in Emacs Lisp, Emanuel Berg, 2015/06/18
- Re: Real-life examples of lexical binding in Emacs Lisp, Udyant Wig, 2015/06/19
- acronymania (was: Re: Real-life examples of lexical binding in Emacs Lisp), Emanuel Berg, 2015/06/19
- Re: acronymania (was: Re: Real-life examples of lexical binding in Emacs Lisp), Rusi, 2015/06/19
- Message not available
- Re: Real-life examples of lexical binding in Emacs Lisp, Emanuel Berg, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Robert Thorpe, 2015/06/17
- Re: Real-life examples of lexical binding in Emacs Lisp, Pascal J. Bourguignon, 2015/06/17