Page 1 of 1

Lazy IF?

Posted: Wed Jul 03, 2024 8:54 pm
by clovepower
Hi, just wondering, as did not find it in the doc, if the clause in IF statement is evaluated in a lazy (C-style) way or not; meaning:

IF (x=0) OR (a=0) THEN....

will (a=0) be evaluated if (x=0)?

Re: Lazy IF?

Posted: Wed Jul 03, 2024 10:08 pm
by spotlessmind1975
Hi clovepower, and thank you for the message! :D
clovepower wrote: Wed Jul 03, 2024 8:54 pm Hi, just wondering, as did not find it in the doc, if the clause in IF statement is evaluated in a lazy (C-style) way or not; meaning:
I don't know if we are referring to the same feature, but in this thread the topic of short circuiting in evaluations was addressed which, I believe, is the same thing as lazy evaluation.

In short, lazy evaluation is a functionality introduced by some medium-level languages, such as C, in order to obtaining notable optimizations, at the cost of avoiding the execution of specific functions. The problem with introducing this type of optimization is that the functions that you avoid performing could have "side effects", and in ugBASIC, side effects are quite common.

However, to simulate it the best thing is to use nested IFs.

Re: Lazy IF?

Posted: Wed Jul 03, 2024 10:47 pm
by clovepower
Hi

Ah, I missed that conversation (since I was searching for "lazy" rather than "short circuit" :D ) but yes, that answers my questions.

At the end, I think it is just necessary to know as the language works, I do not have a strong opinion about short circuiting, even though most more modern languages use it.

Thanks

Re: Lazy IF?

Posted: Thu Jul 04, 2024 6:12 am
by spotlessmind1975
Hi clovepower
clovepower wrote: Wed Jul 03, 2024 10:47 pm Ah, I missed that conversation (since I was searching for "lazy" rather than "short circuit" ) but yes, that answers my questions.
You're right!
I remembered it like that, "lazy", too.
It took me a while to find the exchange again. :D
clovepower wrote: Wed Jul 03, 2024 10:47 pm At the end, I think it is just necessary to know as the language works, I do not have a strong opinion about short circuiting, even though most more modern languages use it.
I think it's more of a flaw on my part. I recognize that I haven't explained the language well in the various manuals and guides. I'm trying to fix it, but anyway thank you for introducing this synonym too, so that other people can search the topic in a more "targeted" way, so to speak.