Questions tagged [let-binding]
57 questions
30
votes
2 answers
what does "let*" ( let asterisk) mean in elisp
I've used let before, but never used let*
what does let* ( let asterisk) mean in elisp?
fyi this one was hard to google because of the asterisk.

american-ninja-warrior
- 3,773
- 2
- 21
- 40
14
votes
1 answer
Emacs let-bound advice
I'd like to temporarily override a function in a piece of code.
Take, for example, the following:
(defun nadvice/load-quiet (args)
(cl-destructuring-bind
(file &optional noerror nomessage nosuffix must-suffix)
args
(list file…

PythonNut
- 10,243
- 2
- 29
- 75
13
votes
2 answers
Bind multiple values directly from list without binding the list itself
Is it possible to assign multiple return values directly to variables without going through a temporary variable in Emacs Lisp?
For example, let's say I have a function that returns a list of two lists:
(defun test-func ()
(setq a '(a b))
(setq…

Håkon Hægland
- 3,608
- 1
- 20
- 51
13
votes
1 answer
Why does a constant in `let` change with repeated calls?
Say we have such a foo function:
(defun foo (e)
(let ((lst '(a b c)))
(delq e lst)))
Then we use it in following way (sequentially evaluating one by one):
(foo 'c) ; => (a b)
(foo 'b) ; => (a)
(foo 'a) ; => nil
(foo 'b) ; => (a)
What…

cutejumper
- 787
- 5
- 12
9
votes
1 answer
Override a function locally, but allow calls to the original function
The advice feature allows modifying the behavior of a function globally. An advice definition can make calls to the original function.
(defadvice foo
(around foo-bar activate compile)
"Always set `qux' to t when running `foo'."
(let ((qux t))
…

Gilles 'SO- stop being evil'
- 21,702
- 4
- 53
- 89
8
votes
3 answers
Lambda in `defun` Captures the Lexical Environment, But in `let` It Doesn't
My example is simplified:
(defvar wtf 10)
(defun f (wtf)
(lambda ()
(cl-incf wtf)))
(setq f (f 20))
(setq g (let ((wtf 30))
(lambda ()
(cl-incf wtf))))
(list (funcall f)
(funcall g)
wtf)
;; ==> (21 11…

shynur
- 4,065
- 1
- 3
- 23
8
votes
2 answers
Is there any difference between '(let (var) ...)' and '(let ((var nil)) ...)'?
I've seen both (let (var) ...) and (let ((var nil)) ...) is there any difference between these statements?

ideasman42
- 8,375
- 1
- 28
- 105
7
votes
1 answer
How to make sure no global variables have been created in a piece of lisp code?
I am writing some lisp code and I would like it not to mess with the global variables in the system. I am therefore being very careful to only use variables within the scope of the let special form.
However, as the code gets longer, it becomes…

Ruy
- 787
- 4
- 11
7
votes
1 answer
Define a function alias within a let binding?
How can I define an alias within a script with let-binding?
I tried
(let (b-s)
(defalias 'b-s 'buffer-string))
But it doesn't work.
I figured out to let-bind the variable where aliases as stored in, but I've not been able to find it.

Gabriele Nicolardi
- 1,199
- 8
- 17
6
votes
1 answer
What's really behind an assignment in Emacs lisp?
[Warning : these are noob questions.]
I'm a beginner in Emacs Lisp and I would like to be sure that I understand well what I'm really doing when I set a value to a variable with setq or let.
Here is a piece of code:
(setq x '(1 2 3 4)) ; define…

Philopolis
- 1,094
- 8
- 14
5
votes
1 answer
Why does a let-bound huge list survive garbage collection after the let form?
Note that the following original test is errorneous and has been superseded by the EDITED version below.
(progn
(message "Before: %S" (memory-use-counts))
(let ((x (make-list 100000000 0)))
(message "Use: %S" (memory-use-counts)))
(message…

Tobias
- 32,569
- 1
- 34
- 75
5
votes
2 answers
Is it possible to use let-binding for setting keys?
in LaTeX mode C-cC-f calls the tex-file function. I performed a litte tweak to that function and I wrote a tex-file-mod function.
Now I'd like to call the tex-file-mode with the same key-binding during some scripts of mine and to restore the default…

Gabriele Nicolardi
- 1,199
- 8
- 17
5
votes
2 answers
Match against a variable with pcase
I'm trying to get pcase to match against a let-bound variable. However, I can't seem to get pcase to recognize the variable correctly.
See this minimal example:
(let ((a 1)) (pcase 2 (a 7))) => 7 ;; as predicted by the docs
(let ((a 2)) (pcase…

PythonNut
- 10,243
- 2
- 29
- 75
4
votes
1 answer
why is a let binding is ignored in compiled function?
I have this function which works perfectly in an uncompiled function. It should let-bind the variable bibtex-completion-bibliography to the result of (org-ref-find-bibliography).
(defun org-ref-valid-keys ()
"Return a list of valid bibtex…

John Kitchin
- 11,555
- 1
- 19
- 41
4
votes
1 answer
Difference between pcase-let & cl-destructuring-bind?
I noticed both pcase-let and cl-destructuring-bind seem to perform the same operation.
Is there any difference or reason to use one instead of the other?
eg:
(pcase-let ((`(,filename ,buf) (pop filename-and-buffer-list)))
;; do stuff.
)
Seems…

ideasman42
- 8,375
- 1
- 28
- 105