Meta Commands
#15
(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:

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

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


Messages In This Thread
Meta Commands - by NasaCow - 11-16-2022, 03:41 AM
RE: Meta Commands - by mnrvovrfc - 11-16-2022, 04:49 AM
RE: Meta Commands - by NasaCow - 11-16-2022, 11:44 AM
RE: Meta Commands - by SMcNeill - 11-16-2022, 04:06 PM
RE: Meta Commands - by mnrvovrfc - 12-06-2022, 04:08 AM
RE: Meta Commands - by bplus - 11-16-2022, 05:13 AM
RE: Meta Commands - by NasaCow - 11-16-2022, 11:47 AM
RE: Meta Commands - by TerryRitchie - 11-16-2022, 04:28 PM
RE: Meta Commands - by SMcNeill - 11-16-2022, 04:48 PM
RE: Meta Commands - by TerryRitchie - 11-16-2022, 06:50 PM
RE: Meta Commands - by RhoSigma - 11-16-2022, 05:22 PM
RE: Meta Commands - by bplus - 11-16-2022, 05:33 PM
RE: Meta Commands - by mnrvovrfc - 11-16-2022, 06:36 PM
RE: Meta Commands - by SMcNeill - 12-06-2022, 05:26 AM
RE: Meta Commands - by mnrvovrfc - 12-06-2022, 06:07 AM
RE: Meta Commands - by SMcNeill - 12-06-2022, 07:12 AM



Users browsing this thread: 8 Guest(s)