All Questions
2 questions
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)
...
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) ...