Re:Emacs Lisp Readable Closures (2013)
by moonchild on Saturday October 16, 2021 @07:17PM
(#28892449)
Here are your snippets in s7, and their output.
(let ((x 3))
(let ((y (lambda (z) (lambda () (+ x z)))))
(format #t "~a~%" (object->string (y 3) :readable))
(format #t "hello~%")
(set! x 5)
(format #t "~a~%" (object->string (y 3) :readable))))
Which gives: (let ((z 3) (x 3)) (lambda () (+ x z)))
hello
(let ((z 3) (x 5)) (lambda () (+ x z)))
And: (let ((x 3))
(let ((y (lambda (z) (lambda () (let ((w 0)) (+ w x z))))))
(format #t "~a~%" (object->string (y 3) :readable))
(format #t "hello~%")
(set! x 5)
(format #t "~a~%" (object->string (y 3) :readable))))
Which gives: (let ((z 3) (x 3)) (lambda () (let ((w 0)) (+ w x z))))
hello
(let ((z 3) (x 5)) (lambda () (let ((w 0)) (+ w x z))))Cool, so it is just more explicit it elisp. Curious if there is a reason for that.
And thanks for running these! I can't really give a reason for not installing a scheme to try myself... :(
Re:Emacs Lisp Readable Closures (2013)
by moonchild on Saturday October 16, 2021 @07:06PM
(#28892370)
> Edit: Actually, I see my confusion, you accidentally printed 'f', not 'g', which I think was your intent?
I am not quite sure what you mean? There was no 'g' at all in my code snippet except for that in 'object->string'. Unless you are mistaking the '9' for one?
Is what happens when I write so late at night. I mistook the 9 for a g, thinking it was showing the body of the lambda. Really, I was just reading it all sorts of wrong.
I still feel this is somehow different, but I can't express the difference well.
Note that I should say I am not at all surprised that scheme could do this, for what its worth. I'm just saying that this feels different.
For example, this
will produce the following messages While this: will print: Is it just that emacs is more explicit about which values were closed over?Edit: Actually, I see my confusion, you accidentally printed 'f', not 'g', which I think was your intent?