Scope of loop variables

Let the developers know what you think of the software and what can be done to either improve the CFDG language or the Context Free program.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
pakin
Posts: 40
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Scope of loop variables

Post 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)) ] {...}

User avatar
MtnViewJohn
Site Admin
Posts: 875
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Scope of loop variables

Post 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.

User avatar
pakin
Posts: 40
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Re: Scope of loop variables

Post by pakin »

Great, thanks!

User avatar
MtnViewJohn
Site Admin
Posts: 875
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: Scope of loop variables

Post 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.

Post Reply