help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Re: Lexical vs. dynamic: small examples?


From: Emanuel Berg
Subject: Re: [External] : Re: Lexical vs. dynamic: small examples?
Date: Sun, 15 Aug 2021 20:49:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Drew Adams wrote:

>> So I wonder again, why not just have two let, one
>> "let-stay" (the variables stay so has to be used and/or
>> passed explicitely), and "let-follow" (the variables follow
>> everywhere the code goes within the let form).
>
> Sorry, I don't follow you. It's not clear to me what you're
> proposing or (more importantly) what problem you think you
> have with the designed behavior.

`let' does two different things, that is confusing, and it is
usually explained with theory - and the terms are confusing as
well - and to set what usage one gets one has to mess with
a variable - what kind of style is that? Just imagine, instead
of `+', `-', etc we would have just one function, "do-math"
which would look for for the value of "operator" to determine
what to do...

So the proposal/question is, instead one could have `let'
_always_ be lexical, and one "with-variables-as" which would
be what is now called "dynamic binding" with let.

"Dynamic" is something that changes over time, but TBH I don't
really see the static/dynamic aspect or difference here?
But OK, for the sake of the discussion, let's call them "letl"
(the lexical one) and "letd" (the dynamic one).

If one did it like that, for practical purposes, the whole
lexical/static vs special/dynamic binding or scope (and
extent) could be dropped, one would just write one docstring
for "letl" and one for "letd"!

(Let's not bring in the issue of nonlocal exits like
exceptions and continuations because if they are indeed
"exceptions" they can be whatever.)

OK, that's let, you also mention global variables, they are
always special/dynamic. However I don't see how that could or
should be done in any other way, how can they be lexical?
If they can't, that issue (the issue of global variables) can
be cancelled out from the discussion as well.

You also mention functions (`defun's) which are lexical in
terms of the their formal parameters (= arguments, only
theoretically, not applied). Because the whole idea with
functions is to modularize and encapsulate I find the concept
of function dynamic scope a bit bizarre, so in a way this
issue (defuns) could be cancelled out as well. But sure, if
someone want them to be dynamic, then why don't we do the same
as I proposed for `let' (which was `let' = "letl", lexical;
and "letd", dynamic), i.e. we would have

  `defun' = "defunl", lexical; and
  "defund", dynamic

?

Then no one would have to mess with `lexical-binding', in any
way (especially not that commented way that reminds me of
a C preprocessor or something), one would just use whatever
one wanted and to explain it to newcomers one would just refer
to the docstrings, no need for CS theory or anything (not
saying it should be forbidden or anything) but for practical
purposes it wouldn't be needed. Everyone would see in the code
- ah, here it is used like that, there it is used the
other way.

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]