Lazy IF?

This forum is dedicated to those who want support programming in ugBASIC.
Questo forum è dedicato a chi desidera supporto per programmare in ugBASIC.
Ce forum est dédié à ceux qui souhaitent prendre en charge la programmation en ugBASIC.
Post Reply
clovepower
Posts: 18
Joined: Sun Jun 23, 2024 7:59 am

Lazy IF?

Post 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)?
spotlessmind1975
Site Admin
Posts: 169
Joined: Fri Oct 06, 2023 8:25 pm

Re: Lazy IF?

Post 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.
clovepower
Posts: 18
Joined: Sun Jun 23, 2024 7:59 am

Re: Lazy IF?

Post 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
spotlessmind1975
Site Admin
Posts: 169
Joined: Fri Oct 06, 2023 8:25 pm

Re: Lazy IF?

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