Questions tagged [closures]
The closures tag has no usage guidance.
11 questions
1
vote
1
answer
52
views
Function closure objects are not created when emacs load files in lexical evironment specified in .emacs init file at startup as emacsclient
I started to use lexical environment to my Emacs 27.1 files on i3 in Ubuntu .
I wrote ;; -*- lexical-binding: t; -*- the first line of the gheg-dired-mode.el and and start Emacs server with:
exec x-...
1
vote
1
answer
39
views
Can I override a function in a function using a closure?
I want to build a modified version of the occur command that obeys to isearch-filter-predicate. I made some tests and I found that I can do it using a modified version of re-search-forward that I ...
3
votes
1
answer
167
views
why lexical environment alist ends with a `t'?
(let ((test 233))
(lambda ()))
;; ==> (closure ((test . 233) t)
;; ==> nil)
I am wondering why not simply choose a proper alist, e.g.:
((test . 233)) ; instead of ((test . 233) t)
As far ...
9
votes
3
answers
528
views
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)
...
2
votes
1
answer
417
views
Reliable lexical binding?
How does one reliably create a lexically bound/scoped variable? Consider the following:
;; -*- lexical-binding: t; -*-
(let ((f load-file-name))
(defun foo () f))
Normally f would be lexically ...
0
votes
1
answer
79
views
How to disassemble an lambda/anonymous function given its hex adress but not name?
Assume that we have:
(defalias 'my-f (lambda () (message "a")))
(byte-compile 'my-f)
=> #f(compiled-function
()
#<bytecode 0x1dc01052127a>)
(setq my-g (byte-compile (...
1
vote
1
answer
88
views
Why funcall doesn't work from a closure
I'm having difficulty to call a function passed as an argument.
Why the following snippet doesn't work, and how can I make it work?
lexical-binding is set to t
(defun on-success (data)
(print "...
5
votes
1
answer
527
views
About closure creation
After reading this article about readable closures, I check that:
Since closures are byte-code function objects, they print readably.
You can capture an environment in a closure, serialize it, ...
0
votes
1
answer
54
views
capture and replay a closure later
I am having a problem working with closures. I hope I can explain this clearly. When I try to start a compilation I typically do it like this:
(let ((dir (get-dir))
(model-root root)
(default-...
2
votes
1
answer
347
views
Why does this straightforward use of a closure fail?
Suppose you save the following code to some file test.el and then do load-file test.el
;;; -*- lexical-binding: t -*-
(let ((closure-vbl 0))
(defun tst ()
(eval 'closure-vbl)))
(tst)
You get ...
6
votes
1
answer
2k
views
How to make local function binding for closure?
For example, when defining the natural number sequence stream, I can use
;; -*- lexical-binding: t; -*-
(defun nats (n)
(cons n (lambda () (nats (1+ n)))))
(nats 0)
=> (0 closure ((n . 0) ...