Questions tagged [lexical-scoping]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
18 votes
2 answers

Why do setq and set quote act differently on let-bound variables with lexical scope?

I had a bug in one of my extensions that eventually turned out to be caused by set not working as I expected: ;; -*- lexical-binding: t -*- (let ((a nil)) (setq a t) (print a)) (let ((a nil)) ...
dshepherd's user avatar
  • 1,281
16 votes
3 answers

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
6 votes
1 answer

Scope in lambda

In my .emacs conf file, I've got this function that adds a hook to set the compile-command based on the mode. It looks something like, (defun set-compile-cmd (mode-hook cmd) (add-hook mode-hook (...
user1943733's user avatar
8 votes
2 answers

'Symbol's value as variable is void' in callback from url-retrieve

When executing the following I get an error: (defun caller (func) (url-retrieve "" (lambda (status) (funcall func)))) (caller (lambda() (message "called"))) Result:...
M Smith's user avatar
  • 279
6 votes
2 answers

Why doesn't "complement" work as a function?

I'm trying to implement the complement function from Common Lisp (CL) in Emacs Lisp, but I'm confused by why defining it as a function (as opposed to a macro) does not work. The macro definition is ...
Tianxiang Xiong's user avatar
2 votes
3 answers

Bringing a function into a lexical environment

I'm using a closure to keep track of some stuff to do with state; I want to be able to ‘include’ a function into that closure, so it can access the state. The only way this is possible is by creating ...
digitalis_'s user avatar
4 votes
1 answer

Make a variable visible to some functions only

Consider the following metacode: ;;; -*- lexical-binding: t -*- (defvar var1 ...) (defvar var2 ...) (defun main () "Main entry point" ...) (defun func1 ...) (defun func2 ...) ... (defun funcn ...)...
antonio's user avatar
  • 1,822
3 votes
3 answers

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
2 votes
1 answer

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 ...
Jonathan Ganc's user avatar