Page 1 of 1

Scope of loop variables

Posted: Sat Mar 24, 2012 10:52 pm
by pakin
According to the Variable declaration wiki page,
The scope of the loop index variable is the loop body and the finally body (if there is one).
Could that be extended to include the loop transform? In some CFDG code I was writing, it would have been handy to be able to have been able to write something like

Code: Select all

loop col = 10 [ x 1 r (myfunc(col)) ] {...}

Re: Scope of loop variables

Posted: Sun Mar 25, 2012 8:15 am
by MtnViewJohn
Yes it is possible. In fact, excluding the loop transform from the scope of the loop index variable was kind of tricky.

It would change the semantics of the loop transform a little. Instead of being evaluated once it would be evaluated on each loop iteration. This would produce different results if the loop transform has random elements.

Code: Select all

loop 10 [x 1..2] { blah blah blah }
would have a random step each iteration. If you wanted to have a random step that was the same for each loop iteration then you would have to do:

Code: Select all

step = 1..2
loop 10 [x step] { blah blah blah }
Anyway, yes I can do this. I will put out another beta release (hopefully the last) when it is ready.

Re: Scope of loop variables

Posted: Sun Mar 25, 2012 11:39 am
by pakin
Great, thanks!

Re: Scope of loop variables

Posted: Sun Mar 25, 2012 12:55 pm
by MtnViewJohn
Whoa! It turns out that the loop transform is be evaluated on each iteration anyway, so the thing with the random loop transform is already occurring. I remember now that I had to do this because color changes in a loop transform are not associative, like the affine transforms used for geometry changes. So there really is no point in not having the loop index scope include the loop transform. It even simplifies the parser.