unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.bjornstam@fastmail.se>
To: guile-devel@gnu.org
Subject: Re: Inconsistency with expressions between definitions
Date: Sun, 24 Sep 2023 13:58:32 +0200	[thread overview]
Message-ID: <fee8a57f-ab13-6399-f407-3219f9c35ba4@fastmail.se> (raw)
In-Reply-To: <87o7hsujrk.fsf@web.de>

Hey!

When you are not referencing x before defining y everything works as you 
want. There is no, so to say, temporal dependency on how the things are 
bound. When you introduce (display x) before actually defining y you 
force letrec* to bind x to the unspecified value, because display has 
side-effects and you don't move around side-effecting code.

If you do (display "heippa!") instead it works as you want.

I believe racket (which does the same optimization) has the same behaviour.

-- Linus Björnstam

Den 2023-09-24 kl. 09:09, skrev Dr. Arne Babenhauserheide:
> Hi,
> 
> while writing a comment to SRFI-245 I think I found an inconsistency in
> the Implementation in Guile.
> 
> This works:
> 
> (define (using-later-variable)
>    (define x y)
>    (define y #t)
>    x)
> (using-later-variable)
> ;; => #t
> 
> This still works:
> 
> (define (using-later-variable)
>    (define x y)
>    (newline)
>    (define y #t)
>    x)
> (using-later-variable)
> ;; => (newline output)
> ;; => #t
> 
> This fails:
> 
> (define (using-later-variable)
>    (define x y)
>    (display x)
>    (newline)
>    (define y #t)
>    x)
> (using-later-variable)
> ;; => #<unspecified>
> 
> Best wishes,
> Arne



  reply	other threads:[~2023-09-24 11:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-24  7:09 Inconsistency with expressions between definitions Dr. Arne Babenhauserheide
2023-09-24 11:58 ` Linus Björnstam [this message]
2023-09-24 16:02   ` Dr. Arne Babenhauserheide
2023-09-25 12:48     ` Linus Björnstam
2023-09-25 13:53       ` Dr. Arne Babenhauserheide

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=fee8a57f-ab13-6399-f407-3219f9c35ba4@fastmail.se \
    --to=linus.bjornstam@fastmail.se \
    --cc=guile-devel@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).