News for hackers. Stuff that matters.
Re:Emacs Lisp Readable Closures (2013) by moonchild on Friday October 15, 2021 @07:23PM (#28884256)
This is scheme. f doesn't return a closure; it is a closure, and it returns a number.
Re:Emacs Lisp Readable Closures (2013) by taeric on Friday October 15, 2021 @10:02PM (#28884987)
Still feels different.

For example, this

    (let ((x 3))
      (let ((y (lambda (z) (lambda ()  (+ x z)))))

        (message "%s" (funcall y 3))
        (message "hello")
        (setq x 5)
        (message "%s" (funcall y 3))))
will produce the following messages

    (closure ((z . 3) (x . 3) t) nil (+ x z))
    hello
    (closure ((z . 3) (x . 5) t) nil (+ x z))
While this:

    (let ((x 3))
      (let ((y (lambda (z) (lambda ()  (let ((w 0)) (+ w x z))))))

        (message "%s" (funcall y 3))
        (message "hello")
        (setq x 5)
        (message "%s" (funcall y 3))))
will print:

    (closure ((z . 3) (x . 3) t) nil (let ((w 0)) (+ w x z)))
    hello
    (closure ((z . 3) (x . 5) t) nil (let ((w 0)) (+ w x z)))
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?

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))))
Re:Emacs Lisp Readable Closures (2013) by taeric on Monday October 18, 2021 @10:52PM (#28914358)
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?

Re:Emacs Lisp Readable Closures (2013) by taeric on Saturday October 16, 2021 @08:12PM (#28892777)
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.