all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yurivkhan@gmail.com>
To: brandelune@gmail.com
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: local binding, too local...
Date: Sat, 8 Dec 2018 13:48:03 +0700	[thread overview]
Message-ID: <CAP_d_8WGbi1JcMy8Bp-1QEsRZnj4h12C-p5xAMzDC2_fUvQzHA@mail.gmail.com> (raw)
In-Reply-To: <0583DE39-42E2-4D05-97F6-3D709DBC73FE@gmail.com>

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.



  parent reply	other threads:[~2018-12-08  6:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-08  2:18 local binding, too local Jean-Christophe Helary
2018-12-08  6:07 ` Drew Adams
2018-12-08  7:39   ` Jean-Christophe Helary
2018-12-08  6:48 ` Yuri Khan [this message]
2018-12-08  7:37   ` Jean-Christophe Helary
2018-12-08  8:02     ` tomas
2018-12-08 14:45       ` Jean-Christophe Helary
2018-12-08 21:59         ` tomas
2018-12-09  2:41           ` Jean-Christophe Helary
2018-12-09  8:45             ` tomas
2018-12-09  9:55               ` Jean-Christophe Helary
     [not found] ` <mailman.5363.1544251700.1284.help-gnu-emacs@gnu.org>
2018-12-08  9:33   ` Rusi
2018-12-08 16:41     ` Stefan Monnier
     [not found]     ` <mailman.5389.1544287285.1284.help-gnu-emacs@gnu.org>
2018-12-08 19:13       ` Barry Fishman

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=CAP_d_8WGbi1JcMy8Bp-1QEsRZnj4h12C-p5xAMzDC2_fUvQzHA@mail.gmail.com \
    --to=yurivkhan@gmail.com \
    --cc=brandelune@gmail.com \
    --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.