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)?
Lazy IF?
-
- Site Admin
- Posts: 171
- Joined: Fri Oct 06, 2023 8:25 pm
Re: Lazy IF?
Hi clovepower, and thank you for the message!
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.
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.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:
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.
-
- Posts: 18
- Joined: Sun Jun 23, 2024 7:59 am
Re: Lazy IF?
Hi
Ah, I missed that conversation (since I was searching for "lazy" rather than "short circuit" ) 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
Ah, I missed that conversation (since I was searching for "lazy" rather than "short circuit" ) 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
-
- Site Admin
- Posts: 171
- Joined: Fri Oct 06, 2023 8:25 pm
Re: Lazy IF?
Hi clovepower
I remembered it like that, "lazy", too.
It took me a while to find the exchange again.
You're right!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.
I remembered it like that, "lazy", too.
It took me a while to find the exchange again.
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.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.