12-06-2022, 06:07 AM
(12-06-2022, 05:26 AM)SMcNeill Wrote: Prior to 1.5 (or 2.0, as the "fix" was listed as a 2.0 achievement), people would write a lot of code such as:If such a function existed it was horrendous. Because "foo" is being compared above twice and each time it calls the function. I would have never done that and have rarely needed recursion in any programming language. That's why I suck at LISP and descendant...
Code: (Select All)FUNCTION foo
IF junk < 10 THEN foo = foo OR 1
IF junk >9 AND foo < 100 then foo = foo OR 2
IF junk > 99 and foo < 1000 THEN foo = foo OR 4
After the fix, all this old code was broken and no longer worked. QB64 had always previously considered a variable inside a function to be the name of the function, and an assignment value. After the fix, only the name on the left side of the equal sign was a name -- the name on the right side of the equal sign was now a recursive call back to the same function.
Lots of old code broke -- after all, people had only had 15 years or so to adapt to coding with the concept that "inside a function, the name references the function itself. If one wants a recursive call, then one should pass a parameter for use with recursion."
Something like this must have driven M$ to change Visual Basic so we lost there (and in Freebasic) the ability to use "GOSUB" and "RETURN", also to make it look even more like C/C++. Otherwise the fix would have been to always require parenthesis right after a function call, even an empty parameter list, except the function's name on LHS of assignment only to set the return value for that function.
The latest code example in your post might have been instead:
Code: (Select All)
FUNCTION foo
IF junk < 10 THEN tempfoo = foo: tempfoo = tempfoo OR 1
IF junk >9 AND foo < 100 then tempfoo = foo: tempfoo = tempfoo OR 2
IF junk > 99 and foo < 1000 THEN tempfoo = foo: tempfoo = tempfoo OR 4
foo = tempfoo
END FUNCTION
But the flaw remains of calling function "foo" once or twice for the sake of making a comparison, and a better chance without short-circuit evaluation. It's just better to give "foo" a parameter to control this better.