For Next parsing bug on trans
Monkey Forums/Monkey Bug Reports/For Next parsing bug on trans
| ||
This should not compile:Function Main() For Local i:Int = 0 To 100 Print i Next x End Because x is not defined. IMHO, If Next [variableName] is allowed, the variable name should be checked for correctness. |
| ||
I personally never use the 'Next var' form of next...does anyone these days? |
| ||
It's a little unrelated (though still with For...Next), but I discovered the other day that I couldn't pass a value to a method and have it used as the "Step" in a For...Next loop. ie. Method Test:Void(stepsize:Int) For Local a:= 0 to 100 Step stepsize DebugLog "a: "+a Next End Method I meant to make a thread and ask why not, but then I saw this and thought it was as good a place as any, sorry for the hijack Ziggy! :) Anyone know why not? I can't remember the error now, but I think it was "unresolved" something....or I may be completely making that up as it's late. |
| ||
I personally never use the 'Next var' form of next...does anyone these days? Sometimes (optional), to make code more read-able. Especially with (long) nested loops, so everybody immediately sees the "Next" is corresponding to i, j, x, y, or z. Function Main:Int() For Local x:Int = 0 To 10 For Local y:Int = 0 To 10 For Local z:Int = 0 To 2 Print String(x)+":"+String(y)+":"+String(z) Next z Next y End For End |
| ||
> I discovered the other day that I couldn't pass a value to a method and have it used as the "Step" in a For...Next loop. It's really an efficiency thing - if step size were variable, loops would have to look something like: var=from_value Repeat If step_value>0 'if step_value is non-const, have to do this at runtime! If var>to_value Exit Else If var<to_value Exit Endif ' 'contents of loop ' var+=step_value Forever It's different in 'C' etc where you explicitly supply the comparison function, whereas monkey (and b3d/bmx) implicitly derive the comparison from the sign of 'step_value'. IMO, this is not nice code for a compiler to dump in your loops without warning just because you used a non-const step_value, so monkey doesn't. |
| ||
I personally never use the 'Next var' form of next...does anyone these days? I've used that sort of thing occasionally, just for readability in complicated code. But it doesn't have to be part of the language. Comments work just as well. Next 'k Next 'n I just noticed that a code block won't indent the first line of code. Later ones are okay. |
| ||
I personally never use the 'Next var' form of next...does anyone these days? Not since the 80's/Early 90's :) |
| ||
I don't use it much, but if it's supported in the language, IMHO it should be well supported, or removed. Whatever you choose is ok, but leaving it wrong is not nice and causes confusion. |
| ||
I would have to side with ziggy. Either it has to be supported (or supported in strict mode?) or be flagged as a compile error. Though personal I do miss typing the extra identifier. |
| ||
IMO, this is not nice code for a compiler to dump in your loops without warning just because you used a non-const step_value, so monkey doesn't. Ahhh I see, thanks for the info Mark. |