2026-07-01 23:47 UTC
Replies (3)
-
@psf@oldbytes.space 2026-07-02 17:32
Aha! If you can arrange for the "closures" to share structure, then you'll have the equivalent of "multiple functions closed over the same environment". Again in muLISP: (let ((alist '(quote ((x . 1))))) (setq do+1 (closure nil '(lambda () (setq x (+ x 1))))) (setq do-1 (closure nil '(lambda () (setq x (- x 1))))) ; Now arrange for both "closures" alists to be shared list structure (rplaca (cddr (caddr do+1)) alist) (rplaca (cddr (caddr do-1)) alist)) (funcall do+1) ; 2 (funcall do+1) ; 3 (funcall do-1) ; 2 (funcall do-1) ; 1 Does any brave soul want to try the equivalent code in Lisp Machine #lisp? ;) If one was gonna do this sorta thing frequently, one could extend the closures package with a macro automating these steps.
-
@psf@oldbytes.space 2026-07-02 00:22
Meanwhile, in a traditional 1960s or 1970s Lisp you would use FUNCTION, which would implement a FUNARG device that closes over the dynamic environment. However, I can't find a vintage environment offhand that lets me demonstrate this. Medley Interlisp-D seems to have dropped support at some point! (BTW, in the Interlisp version of FUNCTION, it appears you still must specify a list of variables to close over, not unlike in Lisp Machine Lisp's CLOSURE. It doesn't snag the whole environment by default. That's the purpose of the mysterious (X) after the LAMBDA.)
-
@simon_brooke@mastodon.scot 2026-07-02 11:50
@psf@oldbytes.space All destructive modification is a dirty hack. In the early days of #Lisp, we were running on machines with very small memories -- I learned Lisp on a machine with under 30Kb of memory available to the Lisp interpreter. On such a machine, destructive modification was sometimes necessary. But we knew that it was generally bad style, to be avoided if possible. Now we have more memory, Lisps with immutable data, like #Clojure, are to be preferred.