3 ms·
Okay, I will try to explain it to the downvoter. Suppose we have a lambda like this: (let ((counter 0)) (lambda () (incf counter)) When we evaluate this
by kazinator 8y ago
Okay, I will try to explain it to the downvoter. Suppose we have a lambda like this:
(let ((counter 0))
(lambda () (incf counter))
When we evaluate this we get a function. It contains the captured lexical environment. If we call that function, the captured counter variable mutates.
Now suppose we had a copy-function library function. I would expect it that if we apply it to this function, we get an object which carries a duplicate of the lexical environment. This means it has its own instance of counter. If we call the original function, the copied function's counter stays the same and vice versa.
I don't remember seeing such a copy-function in any Lisp dialect; there isn't one in ANSI CL. It seems it might be useful, same as the ability to copy a structure or OOP object.
- deleted 8y ago[deleted]