unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: "Alexander Asteroth" <alex@soeven.de>, guile-user@gnu.org
Subject: Re: letrec semantics
Date: Thu, 01 Dec 2022 10:30:05 +0100	[thread overview]
Message-ID: <a1c0c3d1-9419-485f-b6e3-22352d741bb4@app.fastmail.com> (raw)
In-Reply-To: <87sfi379eb.fsf@soeven.de>

Guile implements letrec using letrec*, which most schemes always did, but it wasn't specified due to people wanting to leave possible optimisations on the table. 

The order of letrec is unspecified and schemes are allowed to do whatever order they like. Guile uses the algorithm described in "fixing letrec(reloaded)".

-- 
  Linus Björnstam

On Mon, 28 Nov 2022, at 09:33, Alexander Asteroth wrote:
> Dear all,
>
> I know this topic has been discussed in the past. I found at least one
> discussion in 2003 in guile-user@gnu.org which in the end referred to
> even earlier discussions in comp.lang.scheme. But still I'm confused
> about this and wonder if someone could help with this or point me to a
> discussion that resolves the following issue.
>
> In R5RS it sais about letrec:
>
>>Semantics: The 〈variable〉s are bound to fresh locations
>> holding undefined values, the 〈init〉s are evaluated in the
>> resulting environment (in some unspecified order), each
>> 〈variable〉 is assigned to the result of the corresponding
>> 〈init〉, the 〈body〉 is evaluated in the resulting environmet [...]
>
> As I (and others) understand 
>
>> scheme@(guile-user)> (letrec ((b a)(a 7)) b)
>> $1 = 7
>
> should be equivalent (of course in a new scope) to:
>
>> scheme@(guile-user)> (define b #nil)
>> scheme@(guile-user)> (define a #nil)
>> scheme@(guile-user)> (set! b a)
>> scheme@(guile-user)> (set! a 7)
>> scheme@(guile-user)> b
>> $2 = #nil
>
> but obviously it is't. Why is b assigned to a's reference rather than
> it's value in letrec? ... and would it be a correct implementation of
> R5RS-letrec to return #nil from the letrec above?
>
> Cheers,
> Alex



      parent reply	other threads:[~2022-12-01  9:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  8:33 letrec semantics Alexander Asteroth
2022-11-28  9:25 ` Jean Abou Samra
2022-11-30 17:23   ` Alexander Asteroth
2022-11-28 14:07 ` Taylan Kammer
2022-11-30 17:24   ` Alexander Asteroth
2022-12-01  9:30 ` Linus Björnstam [this message]

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=a1c0c3d1-9419-485f-b6e3-22352d741bb4@app.fastmail.com \
    --to=linus.internet@fastmail.se \
    --cc=alex@soeven.de \
    --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).