10-20-2009 09:30 AM
Today it is the "Select" function. A very common task is to select between two values, and this function does that in a tidy little package. And unlike the case structure, we can easily see what both choices are on the BD. What you end up with is clean, easy to understand code, what could possibly be wrong with that? There is one very important difference between the case structure and the select function, the case structure only evaluates the required case, both cases are evaluated in the Select function. Usually the difference in negligible, or you are choosing between two values that you have calculated anyway. However, a common case where there could be a difference is choosing between an array and the same array with a new value added.
The memory allocation for Build Array goes on in every loop regardless of whether or not it is the desired outcome. In a case structure, only necessary allocations are performed. Don't ask me what this code does or does not do, it is pretty much random.
One thing I sometimes do, but haven't tested is to have build array in every cycle, but choose to append either the new value built into a single element array or an empty array. I assume that appending an empty element doesn't force any memory allocations, but I haven't tested it. I try to stick to case structures now.
Crazy, the array constant is wired to the SR and the node on the while loop, but LV won't show it when I copy.
VIOTD groundrules here.
10-20-2009 10:21 AM
Just small addition: this function also works with Error clusters (some time ago the nugget was already posted here), for example:
Andrey.
10-20-2009 01:30 PM
Darin,
When do we get the VIOTD for the Implies primitive?
I have never used this, and cannot think of a single instance where it simplfies logic. Tomorrow's topic perhaps? 😉
10-20-2009 01:49 PM
nrp wrote:Darin,
When do we get the VIOTD for the Implies primitive?
I have never used this, and cannot think of a single instance where it simplfies logic. Tomorrow's topic perhaps? 😉
That would make a good VIOTD.
I don't want to preempt a future VIOTD. If you search on implies, I think you'll find some good messages from Dennis or one of the other knight's or near knights that explains it pretty well. But it can be used for detecting a given transition like a True to False Transition or a False to True Transition where one of the inputs comes from a shift register. I can't remember which, and the few times I've used it, I've had to find the truth table and work it out. And it almost always seemed like the logic was the opposite of what I wanted. Ultimately, I usually just make my own using a compound arithmetic and inverted inputs or outputs as needed to work for whatever my logic case is.
10-20-2009 02:12 PM
10-20-2009 02:15 PM - edited 10-20-2009 02:16 PM
Ravens Fan nailed it, before the whistle this time. The implies function seems like a perfect VIOTD, and I may still have to get to it someday. However, I came across this thread from a more reputable source.
http://forums.ni.com/ni/board/message?board.id=170&message.id=194432&query.id=1230994#M194432
Still, it may prove hard to resist.
As for tomorrow, my single-handed attempt to rescue the US airline industry continues as I am off on another trip.
Edit: Thanks TST, looks like I came in after the whistle this time...
10-20-2009 04:32 PM
I actually remember seeing that nugget now that it is mentioned. I didn't really get it then and I still don't get it... but am more than happy with using compound logic instead...