Ralf Hemmecke wrote:
> 
> The following demonstrates a bug in the interpreter.
> OK, doesn't seem to be a bug, but still quite hard to figure out what's
> wrong.
> Program is attached.
> 
> The two functions differ only in a line break after the statement
> 
>    n3: Z := x2;
> 
> Thinking a bit about it, maybe
> 
> 
>         n2: Z := x2; for i2 in 1..n2 repeat
>             n3: Z := x2; for i3 in 1..n3 repeat x3 := x3 + 1
> 
> is interpreted as
> 
>         n2: Z := x2; for i2 in 1..n2 repeat n3: Z := x2;
>         for i3 in 1..n3 repeat x3 := x3 + 1
> 
> Thus the error would be clear, since n3 is not available when the second
> loop is started.

I do not see how to relate what you wrote above to the attached
programs.  The second program has

         n2: Z := x2; for i2 in 1..n2 repeat n3: Z := x2;
         for i3 in 1..n3 repeat x3 := x3 + 1

and while this code is wrong, meaning is clear and interpreter
faithfully follows rules.

When you write

         n2: Z := x2; for i2 in 1..n2 repeat
             n3: Z := x2; for i3 in 1..n3 repeat x3 := x3 + 1

then interpreter first joins the two lines and then parses it
using semicolons to separate statements.  The effect is that
'for i2 in 1..n2 repeat n3: Z := x2' is recognized as one
loop and the second loop is executed after the first loop finishes.
So, use braces (or parenthesis) if you want to cram several
statements in a single line and treat them as a block.

> 
> Still the error is very hard to detect if one mixes indentation with
> semicolon.
> 
> So to all... be careful when you use just an indented one-line-block.
> It's not a block, but just a continuation of the previous line.

Exactly.

-- 
                              Waldek Hebisch
[email protected] 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to