unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Self-evaluating function and closure
@ 2019-06-12 20:29 Vladimir Zhbanov
  2019-06-15 19:35 ` John Cowan
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Vladimir Zhbanov @ 2019-06-12 20:29 UTC (permalink / raw)
  To: guile-user


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



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-06-17 14:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-12 20:29 Self-evaluating function and closure Vladimir Zhbanov
2019-06-15 19:35 ` John Cowan
2019-06-16  0:39   ` Mark H Weaver
2019-06-16  0:36 ` Mark H Weaver
2019-06-16  9:02   ` Vladimir Zhbanov
2019-06-16 10:09     ` Mark H Weaver
2019-06-17  8:03       ` Vladimir Zhbanov
2019-06-16  9:47 ` Mark H Weaver
2019-06-16 10:21   ` Thomas Morley
2019-06-16 10:32     ` Mark H Weaver
2019-06-16 10:42       ` Thomas Morley
2019-06-16 11:29 ` Mark H Weaver
2019-06-17  8:48   ` Vladimir Zhbanov
2019-06-17 14:21     ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).