8

Without cl-lib: ;; -*- lexical-binding: t; -*- (defun nats () (letrec ((inner (lambda (n) (cons n (lambda () (funcall inner (1+ n))))))) (funcall inner 0))) (let* ((stream (nats)) (i (car stream))) (while (< i 10) (message "Got %i" i) (setq stream (funcall (cdr stream)) i (car stream)))) See also https://github.com/...


7

You asked: Will be useful to write/build literal closures? Should it be a good practice? any example? Why the closure is not a real type instead of cons? All three questions are answered with the following quote of the elisp manual: However, the fact that the internal structure of a closure is exposed to the rest of the Lisp world is ...


4

There's a few pitfalls here: Using eval with lexical-binding will fail unless you pass it an alist environment argument holding the bindings in question (see F1 f eval) Looking up symbol slots only behaves correctly with dynamic scoping, if you attempt it despite this, you'll get the global value (see F1 f symbol-value) FWIW, this is what I'd call the ...


1

Don't quote callback here: (funcall 'callback data) Quoted, you've said to call the function named "callback" (i.e. using the function slot of the callback symbol). What you want to do is call the function in the value of the callback argument: (funcall callback data)


1

I was experimenting with the reader macros and I think I figured it out. The problem is that I am trying to evaluate, the let values twice. Once when they are first bound and then again when we rebind them. This is not a problem for variables that are strings, because strings always evaluate to themselves. But lambdas evaluate to closures, and you can’t ...


Only top voted, non community-wiki answers of a minimum length are eligible