A list of puns related to "Short circuit evaluation"
I have a formula written like so:
If( mi(state) != playing && doSomeFunkyThingsWith df(S), gv(global),0 )
My question is when the condition is true, does Kustom still evaluate the second output? I don't want this to be calculated unnecessarily.
I was trying to write some conditional breaking out of a loop in a shorter way. Normally I would write something like:
if condition
break
end
But upon testing I noticed that the following one line also worked:
condition && break
Could this in some instances yield different behaviour? And if not might there be another reason not to use this (besides the case when one would also like to evaluate other things when condition
is true)?
Hi all. After the code below is executed, what is the expected value of myVal
? I thought it would be 1, but my code is evaluating it to 2. Why is that?
let myVal = 1 || true ? 2 : 3
Shouldn't a short-circuit evaluation occur once the value of 1
is encountered, resulting in true ? 2 : 3
not being evaluated at all?
Thanks in advance.
Hello, /r/powershell!
I am currently writing a module to interface with a web service run by the NOC at my office. Said web service displays information about devices connected to any campus network switch, but has a particular caveat: Getting information on a switch takes about 60-90 seconds, presumably due to it doing whatever it is it does behind the scenes.
I already have a function which will, given a switch tag number and a login credential (or a valid WebSession that's already logged in), output an object that is more-or-less analogous to what the web service would display - just in an easier-to-automate format.
As it stands, locating a specific device between one or more buildings whose location is unknown requires enumerating all switches in the aforementioned buildings (already done with another script), then piping the list to the function to enumerate the list of devices attached to each switch using Foreach-Object, then piping the list to Where-Object in order to to find the device I'm looking for. This takes quite a long time when you have to run a 60- to 90-second web request for 10-20 switches in a building.
As I'm sure that my search criteria will return at-most one entry, it seems wasteful and inefficient to exhaustively search the rest of the list of switches if I've already found what I'm looking for.
Is there some (elegant) way to terminate the Foreach-Object loop as soon as Where-Object finds something that matches the criteria it's testing against?
Thanks!
I have come to learn that b = 2*a if a<0 else 3*a
can alternatively be expressed as:
b = a<0 and 2*a or 3*a
What just happened and in what sequence?
Because there's practically no resistance.
I'm a Pagan, so I don't celebrate Christmas as either a secular or religious holiday. I don't talk religion at work unless someone asks or gets pushy with their own beliefs, but I also don't pretend to be Christian. I live and work in a very conservative Christian area of the U.S., so this time of year is always annoying with the zealots out in full force. Today, however, I got to enjoy watching one of their heads implode.
One of my coworkers is the most fanatical, hard-core over-the-top conservative Christian I've ever known. He never misses an opportunity to ramrod some Jesus into a conversation and he's always on the most extreme fringe he can find.
Today, while leaving for the long weekend, one of my other coworkers was wishing everyone a good weekend. She looked at me and said something along the lines of "Well, I won't wish you all a merry Christmas, since some of you don't celebrate, so just have a good weekend!" It was a very nice gesture, obviously meant to be inclusive. I appreciated it.
The zealot coworker less so. His face got instantly bright red and he sputtered out "But it's Christmas!" He then darted away and took a different path out of the building and wouldn't talk to anyone when we met back up at the time clock before practically running to his vehicle.
I know it's incredibly petty, but the fact that something so small as someone trying to be inclusive around the holidays will bother him for at least the rest of the evening is bringing me a lot of joy. I'm sure he's going to feel beyond persecuted and will have to let all his Christian friends know the horrors he's faced.
That's definitely going to get me through the rest of the holiday season.
"Iβve been having some very interesting phone calls with some very interesting people who I will not name but some of them rather well-known people who deal in all kinds of behavioral, philosophical, religious, spiritual, meditation, all kinds of ways to attain a state of mind where you really short circuit all of the negative in your life." β Alec Baldwin's instagram ramble
Socializing is like a short circuit for motivation. I'm highly driven towards it, and I waste motivation there. Important insights can motivate posts on Reddit or writing other text to other people, after which I forget and don't apply insights. Socializing regarding hobbies can destroy motivation for that hobby. Also, little bits of socializing are the main thing which motivates me to spend lots of time online.
Now that I think about it, I wonder if only online socializing acts as a short circuit for motivation. It's hard to answer this because I experience little offline socializing.
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.