Jump to content

Ternary operator clarification ($1 = 0) ? ($b = 0) : ($b = 1)


kylomas
 Share

Recommended Posts

AutoIt is known by its lazy evaluation strategy, so no that's never the case. You misunderstood me if you assume something like that.

?

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

That's not "lazy", at least I don't think it's "lazy".

$x = 0 evaluates to false, and since in an And statement all the expressions need to be true, it skips over and continues.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

$y = a()
$x = $y ? $y : 2

Func a()
    Return Random(0, 1000)
EndFunc

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

But it's not possible to know the result in advance. Not even for simple (non-const) variable. For other more usual cases:

You would cahce the return value of function "a" there?

$y = a()
$x = $y ? $y : 2

Func a()
    Return Random(0, 1000)
EndFunc

^ This

This is a situation where you should cache your results in any programming language and situation.

Edited by Richard Robertson
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...