|
From: | Emanuel Berg |
Subject: | Re: How do I pass a variable defined in a wrapping let, to a lambda? |
Date: | Sat, 12 Mar 2022 01:47:55 +0100 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
With static/lexical scope, you get the closure: ;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/geh.el (defun add-one-f (term) (let ((tm term)) (lambda () (1+ tm)) )) ;; (funcall (add-one-f 2)) ; 3 ;; (add-one-f 2) ; (closure ((tm . 2) (term . 2) t) nil (1+ tm)) But with dynamic/special scope, you get only the lambda: ;; this file: ;; https://dataswamp.org/~incal/emacs-init/geh-dynamic.el (defun add-two-f (term) (let ((tm term)) (lambda () (+ 2 tm)) )) ;; (funcall (add-two-f 2)) ; Symbol’s value as variable is void: tm ;; (add-two-f 2) ; (lambda nil (+ 2 tm)) -- underground experts united https://dataswamp.org/~incal
[Prev in Thread] | Current Thread | [Next in Thread] |