Questions tagged [lexical-binding]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
21 views

Lexical-binding and multiple buffers [duplicate]

I want to use a function that is taking advantage of lexical-binding: (defun comp (funcs) "Function composition" (let (f0 ff) (if (not funcs) (lambda (x &rest args) ...
dmw64's user avatar
  • 175
0 votes
0 answers
23 views

Updating old customization code using deprecated lexical-let

Old code (lexical-let ((beg -1) (end -1) (prev-mid -1)) (defun forward-binary () (interactive) (if (/= prev-mid (point)) (setq beg -1 end -1) (setq beg prev-mid)) (if ...
ychaouche's user avatar
  • 207
3 votes
1 answer
164 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 ...
shynur's user avatar
  • 4,638
0 votes
2 answers
85 views

Any way to access a lexical let variable outside of the let?

I need to retrieve a local, lexical, runtime variable from a function, but I'm unable to modify the function to return it because it is from an external library. The variable I'm unable to reach is ...
sextrism's user avatar
3 votes
0 answers
116 views

Using a `defconst' or `defvar' While the Variable Has a Local Binding Sets the Global Binding?

The GNU Emacs Lisp Reference Manual, 12.5 Defining Global Variables: If you use a defconst or defvar special form while the variable has a local binding (made with let, or a function argument), it ...
shynur's user avatar
  • 4,638
3 votes
1 answer
128 views

Warnings about malformed functions when using lexical-let

I have the following function: (defun filter-repl-show-after (line-num) "Show lines after LINE-NUM." (filter-repl--foreach-line (lexical-let ((line-num line-num)) (lambda () ...
Att Righ's user avatar
  • 745
0 votes
1 answer
25 views

Testing lexically-bound, nested functions with ERT

I am experimenting with writing elisp in a more scheme-y style where helper functions are definded inside another function's lexical envirnonment like this (with lexical binding turned on): (defun my-...
dandy's user avatar
  • 13
2 votes
1 answer
327 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 ...
Richard Hansen's user avatar
1 vote
1 answer
197 views

How do I call a function within a lambda?

I would like to define a function that generates lambdas, as such: (defun my-func (FUNCTION) (lambda () (FUNCTION))) But when I evaluate the following (defun my-func1 () (message &...
Tian's user avatar
  • 288
7 votes
1 answer
262 views

What type of variable binding is setq creating?

What type of variable binding or variable or symbol is setq creating, when the variable hasn't been declared prior setq? Given following source code: ;; -*- lexical-binding: t; -*- (defun setq-x () ...
jue's user avatar
  • 4,501
7 votes
1 answer
333 views

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. ...
Ruy's user avatar
  • 839
1 vote
1 answer
106 views

lexical-binding: How to create a let-bound function that recursively calls itself

The custom function below my-jump-to works after being evaluated in a scratch buffer, but does not work when I stick it into a library with lexical-binding non-nil in the header. When byte-compiling, ...
lawlist's user avatar
  • 19k
2 votes
1 answer
779 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)) ; ...
Searene's user avatar
  • 489
0 votes
0 answers
27 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 ...
Tom's user avatar
  • 1,190
1 vote
1 answer
59 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 (...
Damien Cassou's user avatar
1 vote
1 answer
233 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? ...
147pm's user avatar
  • 2,937
3 votes
1 answer
34 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-...
myTerminal's user avatar
6 votes
1 answer
2k 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 ...
147pm's user avatar
  • 2,937
3 votes
2 answers
251 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 ...
zeRusski's user avatar
  • 335
5 votes
1 answer
477 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, ...
anquegi's user avatar
  • 749
3 votes
3 answers
895 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 ,...
erjoalgo's user avatar
  • 863
1 vote
1 answer
720 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+ (...
anquegi's user avatar
  • 749
16 votes
3 answers
757 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, ...
Rose Kunkel's user avatar
0 votes
0 answers
44 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 ...
GergelyPolonkai's user avatar
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) ...
xuchunyang's user avatar
  • 14.4k
2 votes
1 answer
179 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 ...
147pm's user avatar
  • 2,937