Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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) ...
shynur's user avatar
  • 5,890
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.8k