unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Vladimir Zhbanov <vzhbanov@gmail.com>
To: guile-user@gnu.org
Subject: Self-evaluating function and closure
Date: Wed, 12 Jun 2019 23:29:29 +0300	[thread overview]
Message-ID: <20190612202929.GA20126@newvzh.lokolhoz> (raw)


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



             reply	other threads:[~2019-06-12 20:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-12 20:29 Vladimir Zhbanov [this message]
2019-06-15 19:35 ` Self-evaluating function and closure 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190612202929.GA20126@newvzh.lokolhoz \
    --to=vzhbanov@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).