emacs-devel
[Top][All Lists]
Advanced

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

Re: defvar without value


From: Emanuel Berg
Subject: Re: defvar without value
Date: Sat, 11 Apr 2020 01:07:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Bruno Félix Rezende Ribeiro wrote:

>> The supposedly parallel version isn't needed in my
>> experience if there is `let*' [...] Maybe `let' will
>> truly be parallel one day [...]
>
> That’s not the only use of ‘let’, because it’s not
> a weaker form of ‘let*’ as one might first think.
> Both are fundamentally different in their operation
> and ‘let’ is indeed parallel in some strict
> theoretical sense, in the same way ‘let*’ is
> sequential in the same sense. Both forms coincide in
> effect only in the trivial case: when there is no
> reference to (textually) earlier variables being bound
> in the subsequent forms being evaluated to obtain the
> values to be bound to the later ones.

OK, but then the trivial case is the sound one.
Reusing names in `let' bindings is like asking for
trouble. The only exception is when one temporarily
wants to have the old variable another value in another,
remote function. But then it should be super simple,
just assign the new value and invoke the function, and
snap back to normal.

> For instance consider the difference between
>
> #+BEGIN_SRC elisp
>   (let ((x 0))
>     (let ((x (1- x))
>           (y (1+ x)))
>       (cons x y)))
> #+END_SRC
>
> and 
>
> #+BEGIN_SRC elisp
>   (let ((x 0))
>     (let* ((x (1- x))
>            (y (1+ x)))
>       (cons x y)))
> #+END_SRC
>
> The former evaluates to ~(-1 . 1)~ while the latter to
> ~(-1 . 0)~. Both are valid expressions with sensible
> behavior and are not interchangeable. The answer to
> which one to use does *not* follow from the criterion:
> “are the variables to be bound interdependent?”, since
> in both cases they are (and the behavior is
> different).

Well... IMO your example does not demonstrate one being
parallel and one being sequential as much as it is a way
of telling what x is refered to.

And there is a better way to do that, namely calling the
variables different things. And then:

(let ((x 0))
  (let ((a (1- x))
        (y (1+ a)) )
    (cons a y) )) ; DNC

But:

(let*((x 0)
      (a (1- x))
      (y (1+ x)) )
  (cons a y) ) ; (-1 . 1)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

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