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

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

Re: local binding, too local...


From: Yuri Khan
Subject: Re: local binding, too local...
Date: Sat, 8 Dec 2018 13:48:03 +0700

On Sat, Dec 8, 2018 at 9:19 AM Jean-Christophe Helary
<brandelune@gmail.com> wrote:

> In a defun I wrote I have a let* block that does something, then some setf 
> code, then a let block that does something on the values created by setf, but 
> the let block needs a value that it set in the let* block.

The customary way is to put the consumer block within the producer block:

    (defun foo ()
      (let* ((bar '(baz quux)))
        (setf (car bar) 'xyzzy)
        (let ((plugh (cdr bar)))
          (message "%s" plugh))))

> I would like to keep things local, but not *that* local, just *defun* local.
>
> Is there a clean way to declare variables local to a defun and without being 
> locked by let\*? blocks ?

let and let* are *binding* forms, not *assignment* statements. The
bindings go in scope, the body is executed, the bindings go out of
scope.

setq, on the other hand, is an assignment form. If a named variable
exists in the current scope, it will reset its value.

However, the longer a variable is and the broader its scope is, the
more difficult it is to track where and how it it modified.



reply via email to

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