2026-07-02 21:02 UTC
Replies (1)
-
@psf@oldbytes.space 2026-07-02 21:34
@Kazinator@mstdn.ca muLISP has dynamic scope and provides no mechanism to close a function over a particular environment. So strictly speaking it has only open lambdas, not closed lambdas. It certainly doesn't have lexical closures. In certain dynamically scoped Lisps, there is a special form that solves the FUNARG problem by associating a function with a given environment so it can be called in the same environment later. Sometimes the primitive for this is called FUNCTION. muLISP doesn't have that, and looking through manuals for Maclisp and Interlisp, it is not necessarily a reliable solution for the FUNARG problem in those dialects either. I welcome corrections from anyone who has used closures in these old dialects! What is more common, is to find a hacky system for simulating closures by packaging a lambda together with a specified alist of values (not an environment). muLISP provides one: this is what "CLOSURE" is. Lisp Machine Lisp works the same way. In these dialects, the closest you get to a "closure" is something like, (LAMBDA CLOSURE-ARGLIST (CLOSURE-APPLY (QUOTE (LAMBDA (X) (* X A))) (QUOTE ((A . 5))) CLOSURE-ARGLIST)) where a lambda (LAMBDA (X) (* X A)) and an alist ((A . 5)) holding the values "closed over" are stored as arguments of CLOSURE-APPLY. The alist is mutable and used to retain the closure's state between calls. What I've done with my rplaca nonsense is manipulate several of these simulated "closures" to share the same alist, which yields the behavior I wanted, similar to writing (let ... (lambda ...) (lambda ...)) in a lexically scoped Lisp. In any modern system you would have lexical scope directly available, so you would get working closures without the need to perform such unnatural acts.