letrec* not evaluating in defined order

Bug #216663 reported by leppie
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Confirmed
Low
Abdulaziz Ghuloum

Bug Description

Here's a few:

Ikarus Scheme version 0.0.3+ (revision 1447, build 2008-04-13)
Copyright (c) 2006-2008 Abdulaziz Ghuloum

> (letrec* ([b c] [c 1]) b)
1
> (letrec* ([b c] [c b]) c)
> (letrec* ([b c] [c 1]) c)
1

The last 2 should also be signaling an error. Related to similar behavior in letrec?

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 216663] letrec* not evaluating in defined order

On Apr 13, 2008, at 3:02 AM, leppie wrote:
> The last 2 should also be signaling an error. Related to similar
> behavior in letrec?

Yes they should, and I'm aware that I'm not checking for these
kinds of errors, neither for letrec nor for letrec*. Will fix
at some point but not today. :-)

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
leppie (leppie) wrote :

What kind of error should (letrec ((a a)) a) signal?

Petite Chez says:
Error: attempt to reference undefined variable a.

But that is not really correct.

From the R6RS spec it appears it requires it to be of type &assertion.

My feeling is this is a syntax error as it's detectable at compile time.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 216663] Re: letrec* not evaluating in defined order

On Apr 13, 2008, at 6:11 AM, leppie wrote:
> What kind of error should (letrec ((a a)) a) signal?
>
> Petite Chez says:
> Error: attempt to reference undefined variable a.
>
> But that is not really correct.

The value of a letrec-bound variable is undefined until after the
body of the letrec is entered. The value of a letrec*-bound variable
is undefined until after the right-hand-side expression is
evaluated. I don't see how Chez's behavior is "not really correct".
Can you elaborate?

>> From the R6RS spec it appears it requires it to be of type
>> &assertion.
>
> My feeling is this is a syntax error as it's detectable at compile
> time.

In general, such violations are not detectable at compile time, but
they can always be detected at run time.

For example, (letrec ((a (begin (foo) a))) a) evaluates correctly for
some values of foo but not for others, so, it cannot be a syntax error.

Aziz,,,

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

BTW, do you have an example of a correct letrec* program that Ikarus evaluates in an incorrect order? The programs on top are all incorrect, so, no implementation is required to evaluate them correctly. :-)

Revision history for this message
leppie (leppie) wrote :

Unfortunately not :) But as a test, this confirms correct order.

(letrec* ((a (begin (display 'a) b))(b (begin (display 'b) 1))) a)

> The value of a letrec-bound variable is undefined until after the
> body of the letrec is entered.

Yes the value is undefined, but variable is itself is defined. I guess you could interpret that either way.

> In general, such violations are not detectable at compile time, but
> they can always be detected at run time.

I guess I am lucky I can detect these (in IronScheme) at compile time then :)

> For example, (letrec ((a (begin (foo) a))) a) evaluates correctly for
> some values of foo but not for others, so, it cannot be a syntax error.

Would that be for example an escape procedure? If so, then I guess, back to the drawing board for me!

Cheers

leppie

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

On Apr 13, 2008, at 7:46 AM, leppie wrote:
>
>> For example, (letrec ((a (begin (foo) a))) a) evaluates correctly for
>> some values of foo but not for others, so, it cannot be a syntax
>> error.
>
> Would that be for example an escape procedure?

It could be anything that does not return including calling escape
procedures, raising an exception, calling exit, or going in an
infinite loop.

Aziz,,,

Revision history for this message
leppie (leppie) wrote :

That complicates things a bit indeed :)

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

I've marked this as a duplicate of a bug that I just opened since solving that problem solves this automatically.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.