unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.bjornstam@fastmail.se>
To: "Dr. Arne Babenhauserheide" <arne_bab@web.de>
Cc: guile-devel@gnu.org
Subject: Re: Inconsistency with expressions between definitions
Date: Mon, 25 Sep 2023 14:48:56 +0200	[thread overview]
Message-ID: <833458a8-2b58-4eb7-900e-90ba62e5e4e4@app.fastmail.com> (raw)
In-Reply-To: <87fs33v9ft.fsf@web.de>

Hi again!

I am not sure about letrec*, but this should really raise an error in r6rs. You cannot reference a variable before it is assigned. 

I said it "would work in racket" because I believe it uses the same algorithm for deciding when and how and where and how and when things are bound in letrec*. This should also be the case in chez, but chez displays an error. Given I have found the chez is never wrong with regards to R6RS we can say that guiles behaviour is not conformant with r6rs. 

It is also inconsistent with regards to guiles manual, at least if the part on internal definitions is to be believed. 

What I am saying is: congrats, you found a bug :)

Sorry about confusing you. I was never really sure about letrec* behaviour, but you nerdsniped me and I spent some time reading the "fixing letrec (reloaded)" paper, and now things are more clear.

-- 
  Linus Björnstam

On Sun, 24 Sep 2023, at 18:02, Dr. Arne Babenhauserheide wrote:
> Hi,
>
> Linus Björnstam <linus.bjornstam@fastmail.se> writes:
>
>> 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.
>
> This is a technical explanation. It answers "how does this happen?"
> (thank you for that!), but not "why is this the correct behavior?".
>
> The core problem I see: if you inject some logging code between the
> defines, the behavior changes.
>
> I would expect that referencing a variable that can’t yet be used in an
> intermediate expression (between defines) would not cause a (potentially
> subtle) behavior change, but would throw an error: variable used in
> expression that depends on later define.
>
> Racket does not support defines using later defines at all:
>
> $ racket
>> (define (using-later-variable)
>>      (define x y)
>>      (define y #t)
>>      x)
>> (using-later-variable)
> y: undefined;
>  cannot use before initialization
>  [,bt for context]
>
> Best wishes,
> Arne
> -- 
> Unpolitisch sein
> heißt politisch sein,
> ohne es zu merken.
> draketo.de
>
> Attachments:
> * signature.asc



  reply	other threads:[~2023-09-25 12:48 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
2023-09-24 16:02   ` Dr. Arne Babenhauserheide
2023-09-25 12:48     ` Linus Björnstam [this message]
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=833458a8-2b58-4eb7-900e-90ba62e5e4e4@app.fastmail.com \
    --to=linus.bjornstam@fastmail.se \
    --cc=arne_bab@web.de \
    --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).