Questions tagged [lexical-binding]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
34 views

How can I enable lexical binding for Elisp code in org-mode?

I have the following code: #+begin_src elisp (setq lexical-binding t) (let ((a 1)) ; binding (1) (let ((f (lambda () (print a)))) (let ((a 2)) ; ...
0
votes
0answers
23 views

Why symbol-value throws a void-variable error with a let form if lexical binding is on? [duplicate]

Here's a simple example from the manual: ;; Here the symbol ‘abracadabra’ ;; is the symbol whose value is examined. (let ((abracadabra 'foo)) (symbol-value 'abracadabra)) ⇒ foo Why does this ...
0
votes
0answers
11 views

Possible to name closures for easier reading of backtrace?

Let's say I write the following code: (let* ((f (lambda () (debug)))) (funcall f)) This will produce the following backtrace: Debugger entered: nil (closure (bootstrap-version t) nil (debug))() ...
1
vote
1answer
50 views

Lexical binding in a process filter

The code constantly prints server-process: nil instead of the server process name: -*- lexical-binding: t; -*- (let* ((port 1234) (server-process 'something)) (setq server-process (...
1
vote
1answer
118 views

Updating code from lexical-let to lexical-binding: t

This code shows an elisp function (third example) using lexical-let, which is now passe as I understand. How would it be written today with lexical scope now being a quasi-built-in feature of elisp? ...
3
votes
1answer
30 views

Can I determine the difference of declaring (and not declaring) a file to use lexical-binding?

I have been trying to understand what difference it makes if you set the file variable lexical-binding to t for a particular source file. As mentioned in emacswiki that in order to use lexical-...
4
votes
1answer
617 views

Global lexical-binding setting?

I've seen ;;; -*- lexical-binding: t; -*- at the top of a file and (setq lexical-binding t) as how to turn on lexical binding for elisp code, but is there a way to tell Emacs to simply always do ...
3
votes
2answers
125 views

byte-compile and lexical-binding

Could someone in the know please help me understand what's going on here: ;; -*- lexical-binding: t; -*- (let* ((a 0)) (let* ((a 1)) (funcall (byte-compile (lambda () a))))) ;;=> 0 wat? Not ...
4
votes
1answer
185 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, ...
3
votes
3answers
419 views

How to avoid use of `lexical-let`

I have a macro that intends to creates a closure: ; -*- lexical-binding: t -*- (defmacro repro () (let ((kmap-sym (gensym "kmap-"))) `(let ((,kmap-sym (make-sparse-keymap))) (define-key ,...
1
vote
1answer
634 views

Using new features in emacs 27 generators

I want to try new features in emacs 26, I'm using emacs 27, generators and threads, but when I try to use on ielm buffer, I get the same error: ELISP> (iter-defun my-iter (x) (iter-yield (1+ (...
13
votes
3answers
381 views

Defun inside let with lexical binding gives byte-compile warning “the function is not known to be defined”

I want to get the effect of a static variable by using defun inside of let with lexical binding to create a closure. However, when byte-compiling the file, I get a warning. Am I doing something wrong, ...
0
votes
0answers
41 views

Bind a function-local variable to an asynchronous lambda [duplicate]

In wakatime-mode, there are a bunch of process calls that is done by the wakatime-call function. It calls a predefined shell command, so no real magic inside. Now I’d like to make it a bit more error ...
6
votes
1answer
1k 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) ...
2
votes
1answer
152 views

lexical-binding only set at the buffer level?

According to this, it seems to say setting lexical-binding only happens at the individual buffer level, i.e. I could not do (setq lexical-binding t) in my init file and have it apply to all subsequent ...