all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Real-life examples of lexical binding in Emacs Lisp
Date: Wed, 17 Jun 2015 22:22:14 +0200	[thread overview]
Message-ID: <877fr2ulu1.fsf@debian.uxu> (raw)
In-Reply-To: jwvh9q6e761.fsf-monnier+gnu.emacs.help@gnu.org

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


  parent reply	other threads:[~2015-06-17 20:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29  8:28 Real-life examples of lexical binding in Emacs Lisp Marcin Borkowski
2015-05-30  8:28 ` Tassilo Horn
2015-06-14 10:52   ` Marcin Borkowski
     [not found]   ` <mailman.4976.1434279182.904.help-gnu-emacs@gnu.org>
2015-06-14 11:31     ` Pascal J. Bourguignon
2015-06-16 23:48       ` Jim Diamond
2015-06-17  0:06         ` Emanuel Berg
2015-06-17  6:23           ` Andreas Röhler
     [not found]           ` <mailman.5136.1434522217.904.help-gnu-emacs@gnu.org>
2015-06-17 10:49             ` Pascal J. Bourguignon
2015-06-17 10:53               ` Pascal J. Bourguignon
2015-06-17 14:42                 ` Stefan Monnier
2015-06-17 16:19                   ` Andreas Röhler
2015-06-17 19:30                     ` Tassilo Horn
     [not found]                   ` <mailman.5171.1434557990.904.help-gnu-emacs@gnu.org>
2015-06-17 17:12                     ` Stefan Monnier
2015-06-17 20:22                   ` Emanuel Berg [this message]
2015-06-17 22:13                     ` Pascal J. Bourguignon
2015-06-17 23:46                       ` Emanuel Berg
2015-06-18 14:57                     ` Udyant Wig
2015-06-18 15:47                       ` Emanuel Berg
2015-06-19 13:49                         ` Udyant Wig
2015-06-19 17:41                           ` acronymania (was: Re: Real-life examples of lexical binding in Emacs Lisp) Emanuel Berg
2015-06-19 17:53                             ` Rusi
2015-06-17 20:33             ` Real-life examples of lexical binding in Emacs Lisp Emanuel Berg
2015-06-17 22:07               ` Robert Thorpe
2015-06-17 22:17                 ` Pascal J. Bourguignon
2015-06-17  0:43         ` Pascal J. Bourguignon
2015-06-17 16:02         ` Phillip Lord
     [not found]         ` <mailman.5167.1434556959.904.help-gnu-emacs@gnu.org>
2015-06-23 23:49           ` Jim Diamond
     [not found] ` <mailman.3950.1432974543.904.help-gnu-emacs@gnu.org>
2015-05-30 12:59   ` Pascal J. Bourguignon
2015-06-14 10:55     ` Marcin Borkowski
     [not found]     ` <mailman.4977.1434279342.904.help-gnu-emacs@gnu.org>
2015-06-14 20:04       ` Stefan Monnier
2015-06-14 21:44         ` Pascal J. Bourguignon
2015-06-14 21:49           ` Pascal J. Bourguignon
     [not found] <mailman.3883.1432888152.904.help-gnu-emacs@gnu.org>
2015-05-29  9:30 ` Joost Kremers
2015-05-29 11:12   ` Andreas Röhler
2015-05-29 12:13     ` Dmitry Gutov
2015-05-29 16:21     ` Phillip Lord
2015-05-29 16:50       ` Yuri Khan
2015-05-29 12:28 ` Pascal J. Bourguignon
2015-05-29 17:16   ` Andreas Röhler
2015-05-29 18:43 ` Emanuel Berg
2015-05-30  5:49 ` Rusi
2015-05-30 12:50   ` Pascal J. Bourguignon
2015-05-30 15:23     ` Rusi
2015-05-30 15:50       ` Pascal J. Bourguignon
2015-05-30 16:21         ` Rusi
2015-05-30 16:03   ` Emanuel Berg
2015-05-30 16:32     ` Rusi
2015-05-30 16:54       ` Pascal J. Bourguignon
2015-05-30 17:10         ` Rusi
2015-05-30 19:12           ` Pascal J. Bourguignon

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=877fr2ulu1.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@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.