LabVIEW Channel Wires

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: AQ's Anonymous Closures Post

(This is a response to a post AQ made last Friday, which appears to have been deleted.  I won't duplicate his text here, but it discussed a way to use channels to implement something that is functionally very similar to anonymous closures.  I don't know why the other post was deleted, but if the topic should not be discussed in public feel free to delete this post as well.)

Naming:  I agree anonymous closures isn’t a good name for this implementation.  Conceptually, closures are inserted into the calling code.  Here the data is being “extracted” from the calling code to be operated on.  Functionally identical, but conceptually very different.  Coroutines more accurately matches that concept in my opinion.  Plus, this leaves room for "closure" structures in the future if NI ever decides to support them.

How to teach it to CLADs:  I thought you did a fine enough job explaining it.  I showed the pics to my coworker, a fresh-out-of-school engineer who I’ve been mentoring in Labview for the last 14 months.  He didn’t have any trouble understanding the idea.  Granted, I don’t think he understood how powerful this is or how he would use it, but he got the idea.

Now the real reason this idea grabbed my interest…

I like using collections in my code and implement them as classes.  In text languages, collections permit “For Each…” syntax to iterate over a collection.  I haven’t found a way to do that in Labview I’ve been satisfied with.  (Usually I provide a method that returns an array of keys, then remove each item from the collection, operate on it, and add it back to the collection.  Depending on how the collection is implemented, this can be quite expensive.)  I haven’t played with it yet, but it looks like implementing For Each behavior using coroutines will operate on the items inline rather than requiring modifying the collection itself.  Good stuff!

Question:  Using the ClosureSnippet as an example, is it possible (or even desirable) for a coroutine to be optional?  In other words, can SortArray.vi have a default sorting implementation that is used if a coroutine is not supplied?  (Aside from the obvious route of including a UseCoroutine boolean on the conpane?

0 Kudos
Message 1 of 1
(3,437 Views)