09-17-2015 12:49 AM
As pointed out, replacing recursion with a stack often makes it easier to understand, but even if you stick with recursion, you might be reinventing the wheel. There are at least two popular tools which take clusters and convert them to strings - the MGI read/write anything VIs and the OpenG variant VIs (specifically, the variant config VIs). You might be able to use them and get away with it.
You can also flatten some data structures directly to JSON using the JSON primitives.
09-18-2015 07:59 AM
@nathand wrote:
but I wouldn't recommend writing a lot of recursive LabVIEW code.
I've used recursion quite a lot. It works particulary well with dynamic-dispatch methods in LVOOP.
09-18-2015 08:06 AM
@nathand wrote:
LabVIEW does not do this, so recursive calls will use more memory and incur a performance penalty versus a loop.
Depends on the depth of the tree-like structures one is passing over. Clusters and subclusters of up to five levels deep means five clones of the reentrant fuction, which can be endlessly reused. The initial creation of those five has some overhead, after which the only overhead is the subVI call.
09-18-2015 09:46 AM
@tst wrote:
There are at least two popular tools which take clusters and convert them to strings - the MGI read/write anything VIs and the OpenG variant VIs (specifically, the variant config VIs).
I got it working so I'm going to leave it as-is but thanks for mentioning these tools. Just downloaded both MGI and OpenG tools packages and I'm having a lot of fun browsing the new possibilities.
09-22-2015 10:34 AM
Not sure if this is its actual name but I've always heard of it as While Loop Recursion. Where instead of calling yourself in a truely recursive way, you just use a while loop that pushes and pulls things to process, and you keep going until there is no more things to process.
The typical example I use of this the native Recursive File List.vi in the Advanced File I/O palette. It finds all files and folders in a folder, then if there are folders in that folder, it adds them to the list of folders to process, which may add more folders, and more folders, etc. It could have been done with recursion but I think debugging that would be more difficult where here you can clearly see the stack of folders to be processed.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord