2026-06-19 06:04 UTC
Replies (2)
-
@psf@oldbytes.space 2026-07-01 23:47
I found a weird thing about "Lisp machine closures", at least as implemented in muLISP. In ordinary lexically-scoped #Lisp, multiple functions can close over the same variables. (let ((x 1)) (defun do+1 () (setq x (+ x 1))) (defun do-1 () (setq x (- x 1)))) (do+1) ; 2 (do+1) ; 3 (do-1) ; 2 (do-1) ; 1 In muLISP it's considerably harder to do this because the closure function creates a new alist of "closed-over values" per closure, so they are all independent. Judging by the Lisp Machine Manual, things appear to work the same way over there too. (let ((x 1)) (setq do+1 (closure '(x) '(lambda () (setq x (+ x 1))))) (setq do-1 (closure '(x) '(lambda () (setq x (- x 1)))))) (funcall do+1) ; 2 (funcall do+1) ; 3 (funcall do-1) ; 0 (do-1 is a logically separate closure) (funcall do-1) ; -1 But what you can do is close over a list and do destructive list operations. Then everyone's alist has a reference to the same list, so the closures communicate by destructively modifying the list. I have no idea if this is just a dirty hack or if people used this in practice. (let ((x (list 1))) (setq do+1 (closure '(x) '(lambda () (incf (car x))))) (setq do-1 (closure '(x) '(lambda () (decf (car x)))))) (funcall do+1) ; 2 (funcall do+1) ; 3 (funcall do-1) ; 2 (funcall do-1) ; 1
-
@weekend_editor@mathstodon.xyz 2026-06-19 15:58
@psf@oldbytes.space I spent a lot of time on lispms in the 80s, and never saw anything like this. Since they use QUOTE rather than FUNCTION on the enclosed lambda, isn't it hopeless to compile this? OTOH, I've also never touched muLISP. Maybe there was only an interpreter.