1. Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

Robert Craig wrote:
> 
> Mario Steele wrote:
> > I just wanted report this bug before 2.5 went Final, cause this is indeed
> > a major bug.  I've tested this under 2.5 and 2.4, and 2.4 works correctly,
> > but 2.5 does not.  You can see it happening when you invoke the trace
> > like I have it written.
> > 
> > }}}
<eucode>
> > with trace
> > sequence stack
> > 
> > constant NewValue = {0,0,1,0}
> > stack = {}
> > 
> > trace(1)
> > function recursive_call(integer i)
> > 	integer ib
> > 	stack &= 0
> > 	ib = length(stack)
> > 	stack[ib] = NewValue
> > 	for x = 1 to 4 do
> > 		if stack[ib][i] = 0 then
> > 			stack[ib][i] = recursive_call(i+1)
> > 		end if
> > 	end for
> > 	return ib
> > end function
> > 
> > integer i
> > i = recursive_call(1)
> > ? stack
> > machine_proc(26,0)
> > </eucode>
{{{

> 
> It's not a bug.
> It's a change in the way things work in a rare,
> ambiguous, and undocumented area.
> 
> I should mention this in the 2.5 alpha release notes
> or somewhere.
> 
> In order to efficiently support the new $ feature,
> I had to change the order of operations when subscripts
> are performed on the left-hand-side of an assignment. e.g.
> 
> stack[ib][i] = recursive_call(i+1)
> 
> In 2.4, all expressions are evaluated first, then
> the lhs subscripting is performed and the rhs value is assigned.
> 
> In 2.5, I (generally) need to perform each lhs subscript as I go along,
> from left to right, before evaluating the subscript expression
> that comes after it, since I may need to know the proper value of $
> in the subsequent subscript expression.
> 
> In 2.4, you obviously counted on recursive_call() being completed
> before the subscripted assignment was done, and you counted
> on stack being changed by the side-effects of that call, before
> the assignment to stack was done.
> None of this was documented in the Reference Manual. 
> You just tried it, and it worked.
> 
> In 2.5, the lhs var being subscripted will keep its original
> value (I just increment its ref count), and will then be 
> modified by the assignment. The effect of any side-effects 
> on that var (i.e. stack) will be lost
> as the assignment is completed. If I don't preserve the original
> value, I can easily have crashes due to your having 
> "pulled the rug out from under me" while I'm in the middle of
> trying to subscript a now non-existent value. And, no, I don't
> want to insert checks all over the place for this bizarre situation.
> 
> You only have to worry about this change if you are doing 
> a subscripted assignment with multiple subscripts on the lhs,
> and in the same statement you are calling a function 
> that has the side-effect of modifying the lhs var (even as it
> is being assigned-to).
> 
> You can make things work the way you want, and also
> make your code more readable, by performing the function call 
> in a separate statement before trying to modify the lhs variable.
> 
> Regards,
>    Rob Craig
>    Rapid Deployment Software
>    <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>
> 

Couldnt you just have made foo[$] translate to foo[length(foo)] in the
Euphoria IL?

-------------------------------------------
Euphoria v2.5 Rocks!!!

new topic     » topic index » view message » categorize

2. Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

Vincent wrote:
> Couldnt you just have made foo[$] translate to foo[length(foo)] in the
> Euphoria IL?

I've implemented $ efficiently, so it takes advantage of
the subscripting that has occurred so far (moving left to right),
rather than recalculating it. 
    foo[i][j][k][$] 
implemented simply as: 
    foo[i][j][k][length(foo[i][j][k])]
would not be very efficient.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

3. Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

On Sun, 13 Feb 2005 14:17:34 -0800, Robert Craig
<guest at RapidEuphoria.com> wrote:

>I've implemented $ efficiently, so it takes advantage of
>the subscripting that has occurred so far (moving left to right),
>rather than recalculating it. 

I see. I would normally expect the subscript values to be evaluated
first of all (before the RHS), so yes, I can see a performance gain

I previously came up with (to my mind) a slightly clearer case:

sequence stack
function fn()
	stack={0}
	return 1
end function

stack[1]=fn()
?stack


In 2.4 this would display {1}, in 2.5 this somewhat more correctly
causes the error "variable stack has not been assigned a value".
Of course stack[length(stack)]=fn() gives the same error in both 2.4
and 2.5.

I only mention this for documentation purposes,
Pete

new topic     » goto parent     » topic index » view message » categorize

4. Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

Vincent wrote:
> 
> 
> Couldnt you just have made foo[$] translate to foo[length(foo)] in the
> Euphoria IL?

This would be much less efficient for cases where '$' is really useful
(and is actually more than simple syntactic sugar).  I used my IL code
disassembler to show you why:

For your simple case, you can see that identical code is emitted:

     5: 042 103 105                      # LENGTH: [foo:103] => [_temp_:105]
8: 025 103 105 105                  # RHS_SUBS: [foo:103] sub [_temp_:105]
     =>
                                         #     [_temp_:105]
    12: 036 104 105                      # QPRINT: [_temp_:105]

    15: 058 4                            # STARTLINE: 4 <<? foo[length(foo)] >>
    17: 042 103 105                      # LENGTH: [foo:103] => [_temp_:105]
20: 025 103 105 105                  # RHS_SUBS: [foo:103] sub [_temp_:105]
    =>
                                         #     [_temp_:105]
    24: 036 104 105                      # QPRINT: [_temp_:105]

If there is some additional subscripting, however, you can see that a simple
translation of $ to length(foo[3][4]) results in more code, and therefore
slower execution:

? foo[3][4][$]:

    27: 058 6                            # STARTLINE: 6 <<? foo[3][4][$] >>
29: 025 103 106 105                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:105]
33: 092 105 107 105                  # RHS_SUBS: [_temp_:105] sub [LIT
    4:107] =>
                                         #     [_temp_:105]
    37: 042 105 108                      # LENGTH: [_temp_:105] => [_temp_:108]
40: 092 105 108 108                  # RHS_SUBS: [_temp_:105] sub
    [_temp_:108]
                                         #     => [_temp_:108]
    44: 036 104 108                      # QPRINT: [_temp_:108]

? foo[3][4][length(foo[3][4]):
47: 058 7                            # STARTLINE: 7 <<?
    foo[3][4][length(foo[3][4])]
                                         #     >>
49: 025 103 106 108                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:108]
53: 092 108 107 108                  # RHS_SUBS: [_temp_:108] sub [LIT
    4:107] =>
                                         #     [_temp_:108]
57: 025 103 106 105                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:105]
61: 092 105 107 105                  # RHS_SUBS: [_temp_:105] sub [LIT
    4:107] =>
                                         #     [_temp_:105]
    65: 042 105 105                      # LENGTH: [_temp_:105] => [_temp_:105]
68: 092 108 105 108                  # RHS_SUBS: [_temp_:108] sub
    [_temp_:105]
                                         #     => [_temp_:108]
    72: 036 104 108                      # QPRINT: [_temp_:108]

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

5. Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

Hi there Rob and others,

I take the code:

sequence s
s[1]=12345

{GENERATES AN ERROR}
to be the 'rule' here, where it's quite logical that you wont be
able to assign anything to a sequence element that simply isnt
there yet!  I've taken this to be the rule since day 1, and im 
quite sure none of my programs have violated this rule because i've
always respected that one rule outlined by those two simple lines
of code.  It doesnt matter to me if you can call a function under
v2.4 and be able to assign to elements that arent there before
the call because i considered it bad practice all along and so avoided
doing this.  It is interesting that you can do this under 2.4
and not 2.5 though, so now i guess the 'rule' will get written in
stone?

In the future perhaps it's better to keep default behaviours though, so as to
give previous users nothing to complain about.  It's a real bother when
you've taken the time to come up with a clever coding solution that takes
advantage of the language to it's fullest extent only to find that several
months down the road it's changed so you cant use your well thought-out
coding scheme anymore.

When i created my dollar sign remover program i assumed $ would
replace 'length()' exactly too.  I made sure i replaced EVERY occurance
of $ with length().  Perhaps this is one program that doesnt work
'exactly' as '$' would under 2.5 ?


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

6. Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

Robert Craig wrote:

> Pete E wrote:
>> So how about for the cases where the $ operator is not used, revert to
>> the previous method of subscripting (as in 2.4) so that programs that
>> require backwards compatibility will not break?
>>
>> If the subscripting does use $, then use the efficient method that
>> refcounts (protects) the LHS variable.  We don't care about backwards
>> compatibility in this case, since the $ operator is new to version 2.5.
>
> That would assist in getting over the current
> compatibility glitch, but what happens when someone in the future
> changes from using length() to using $ or vice versa, and
> mysteriously the order of expression evaluation changes?

That would be a nightmare. Using the same version of the interpreter/
compiler, a program IMHO should run exactly the same way, regardless
whether length() or $ is used.

<snip>

Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu