[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Self-evaluating function and closure
From: |
Vladimir Zhbanov |
Subject: |
Self-evaluating function and closure |
Date: |
Wed, 12 Jun 2019 23:29:29 +0300 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Greetings,
I have tried almost a textbook example with Guile 2.2.4:
scheme@(guile-user)> (define (function-generator)
(let ((func #f))
(lambda () (set! func (let a () a)) func)))
scheme@(guile-user)> (define x (function-generator))
scheme@(guile-user)> (define y (function-generator))
scheme@(guile-user)> x
$20 = #<procedure f9f9d0 at <unknown port>:562:25 ()>
scheme@(guile-user)> y
$21 = #<procedure bf2660 at <unknown port>:562:25 ()>
scheme@(guile-user)> (x)
$22 = #<procedure a ()>
scheme@(guile-user)> (y)
$23 = #<procedure a ()>
scheme@(guile-user)> (eq? (x) (y))
$24 = #t
The result is unexpected for me, I expected a new self-evaluating
procedure every time I run the function-generator procedure (and
it works differently with Guile 2.0, IIUC, cannot check just now).
AFAICS, Guile creates a toplevel procedure "a" while it should not
do so.
scheme@(guile-user)> a
$25 = #<procedure 109aa90 at <unknown port>:422:25 ()>
Questions:
- Is this a bug?
- Is there a way to work around this (either using the above 'let'
construct or anything else)?
Thanks in advance
--
Vladimir
(λ)επτόν EDA — https://github.com/lepton-eda