[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

letrec semantics

From: Alexander Asteroth
Subject: letrec semantics
Date: Mon, 28 Nov 2022 09:33:54 +0100
User-agent: mu4e 1.8.11; emacs 28.2

Dear all,

I know this topic has been discussed in the past. I found at least one
discussion in 2003 in 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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]