From: tomas@tuxteam.de
To: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function?
Date: Wed, 9 Jun 2021 08:09:59 +0200 [thread overview]
Message-ID: <20210609060959.GA21706@tuxteam.de> (raw)
In-Reply-To: <YL/XTZgw0tlWI18T@protected.localdomain>
[-- Attachment #1: Type: text/plain, Size: 2391 bytes --]
On Tue, Jun 08, 2021 at 11:47:09PM +0300, Jean Louis wrote:
> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-06-08 23:23]:
> > OK. Since you can't go back in time, you can set the variable
> > for a part of the program which isn't yet compiled. Otherwise
> > you'd have to "un-compile" your program first, right?
>
> Should I worry now? Sounds like I should
>
> (defun my-hello (string)
> (interactive "sYour name: ")
> (eval (list 'message-box (concat "Hello " string))))
>
> If that works dynamically then my function should also work.
For some value of "work", yes. I propose doing the following
experiments:
Start always in a new "lisp interaction buffer". E.g. do
* Experiment 1
C-x b *my-new-experiment*, then M-x lisp-interaction-mode
First, type in
lexical-binding
...with point at the end of the line (or the next line) C-x e to
eval this, make sure the minubuffer shows "t". We have lexical
binding.
Now enter this
(let ((some-var 42)) ; just to set up some scope
(eval '(setq that-other-var 43))
(message "%S\n" that-other-var))
You'll see "43" in your minibuffer. We managed to set the dynamically
"defined" variable "that-other-var" to 43. Yay! Now enter
that-other-var
...and again C-x e. Minibuffer says... 43. The variable escaped the
scope. Bad variable, but hey, that's how setq goes, no?
* Experiment 2
Make new lisp interaction buffer, as above. Make sure you have
lexical binding (when experimenting, always change at most one
thing at a time, right?). Now:
(let ((some-var 42)
(that-other-var 44)) ; bind that-other-var locally
(eval '(setq that-other-var 43))
(message "%S\n" that-other-var))
Again, minibuffer says 43. Now...
that-other-var
...and C-x e. What does minibuffer say? Is that right or wrong?
Explain.
I guess you'll need a more differentiated model than just "works".
Works how? Do you want it to "work" like that? If yes, then fine.
And then there is the question of collaboration: if you want others
to understand your programs (and vice-versa), then there are even
more (!) criteria.
A very wise person [1] once said that he doesn't write programs
to get the computer to do what he wants, but to convince his
colleagues that the computer is doing the right thing.
Cheers
[1] ISTR that it was Donald Knuth.
- t
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2021-06-09 6:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 13:10 Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 13:41 ` [External] : " Drew Adams
2021-06-08 14:47 ` Jean Louis
2021-06-08 17:14 ` Jean Louis
2021-06-08 18:31 ` tomas
2021-06-08 18:37 ` Oops function? tomas
2021-06-08 19:27 ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:03 ` tomas
2021-06-08 20:06 ` Sorry again tomas
2021-06-08 20:12 ` [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Jean Louis
2021-06-08 20:23 ` tomas
2021-06-08 20:38 ` Jean Louis
2021-06-08 20:47 ` Jean Louis
2021-06-09 6:09 ` tomas [this message]
2021-06-09 6:42 ` Jean Louis
2021-06-09 6:51 ` tomas
2021-06-09 7:03 ` Jean Louis
2021-06-09 7:39 ` tomas
2021-06-09 8:22 ` Jean Louis
2021-06-09 8:54 ` tomas
2021-06-09 10:56 ` Jean Louis
2021-06-09 11:33 ` tomas
2021-06-09 14:39 ` Jean Louis
2021-06-09 16:41 ` tomas
2021-06-10 2:10 ` Robert Thorpe
2021-06-10 6:56 ` Jean Louis
2021-06-11 6:33 ` Robert Thorpe
2021-06-11 7:03 ` Jean Louis
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=20210609060959.GA21706@tuxteam.de \
--to=tomas@tuxteam.de \
--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.