Replies: 2 comments
-
Yes agreed. For low level loop constructions, you have to declare the variable outside the loop. For some constructions you can also declare it the loop BUT it is NOT local to the loop, it persists so the same loop again will cause a duplicate symbol error. And for some loops, the variable is auto declared and local to the loop. It's a mess. Localising the variable is done (see the grammar) by nesting it in a procedure then calling the procedure so the variable becomes local to the procedure. The procedure call is then inlined. The nasty is that a goto inside the procedure to outside the procedure is a non-local goto until after inlining, so the inlining is mandatory. The problem with local loop variables is that they don't survive the loop and you often want them to. On the other hand, if you export the control variable outside the loop, you can only declare the variable in that loop and it's seen everywhere. https://github.com/felix-lang/felix/blob/master/src/packages/grammar.fdoc around line 3600 stuff on loops. As you can see, most of the loops are implemented in the grammar using gotos. |
Beta Was this translation helpful? Give feedback.
-
RAW LOOPSAll the raw loops are flat, meaning, you can jump into the middle of one, the body does not define a scope. This means the forms with C like loopsThe initial statement may assign or define the control variable. The control variable overshoots.
count upsThe control variable does not overshoot.
count downsThe control variable does not overshoot.
slice ups
iteratorThese are high level loops with a body forming a separate scope.
|
Beta Was this translation helpful? Give feedback.
-
For newbies, there is an unnecessary cognitive hurdle required to get for loops correct.
When do you use a var and when not to?
The question is: Could this be eliminated, to make it easier to use Felix?
Example:
(The 3rd and 5th loops in the following code)
When do you need to add the
var
to the for loop? This is unnecessary thinking on the part of the programmer, and results in extra bug fixing when coding with the language.If Felix could determine that the variable doesn't exist and make it a local var to the
for
loop, it would make things simpler and easier (no var required in the syntax. Define it outside the loop, or let Felix define it for you for looping purposes).Beta Was this translation helpful? Give feedback.
All reactions