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

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

Re: Lexical vs. dynamic: small examples?


From: Emanuel Berg
Subject: Re: Lexical vs. dynamic: small examples?
Date: Sat, 14 Aug 2021 05:56:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Eduardo Ochs wrote:

> is quite nice - especially because of its last part, that
> inspects two different getter-setter pairs, shows that their
> lexical environments are the cadrs of their closures, and
> shows that `geta' and `seta' share the same lexical
> environment and that `getb' and `setb' share another lexical
> environment...
>
> My current knowledge of lexical binding stops there, though.
> Any comments (or help) would be very welcome...

OK, IIUC with lexical (AKA static) binding the variable's
value is determined by the code and the scope, so you can
always find out what value it is by looking at that and move
within that and only that delimited area.

Move outside of that the variable bindings don't mean
anything. Move from A to B, and you wanna know what goes on in
B, it doesn't matter what happened in A and you look for the
answer in BB (B and only B).

Have a look:

  (let ((a 1))
    (do-something a) ; 1 is here
    (do-something-else) ) ; but if a is referenced here, it isn't 1
                          ; not the same a!

This is more useful and clear to the regular user and perhaps
the advanced one as well and most people should think this
natural from experience but also from what makes sense looking
at that code :) This style seems to make for more independent,
well-defined, more reusable and less vulnerable units of
computation...

With dynamic binding however the variable's value is rather
read from the top of a stack data structure, everyone who sets
the value then pushes it onto the top of the stack - and when
it is unset that value is popped - but even so if it is
thereafter referenced, it is still defined, one just looks for
the plate below.

This style is more like one mastermind keeping track of
everything thru telepathy...

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




reply via email to

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