I wrote the attached recursive VIs some time ago, just to see how that could be
implemented. The VIs don't use reentrency or Call by reference or anything (as far
as I remember they were done in LV 2.52 or so). They use shift registers and, most
important, a VI that implements a FIFO stack. Admittedly, the VIs are quite
cryptic, but they work and demonstrate the principle.
Regards
Franz Ahlers
(P.S.: the VIs calculate N! and f(N)=N*f(N-1)*f(N-2). The second function was made
up by me to demonstrate a little bit more complicated case than just N!)
John Lum schrieb:
> "Kevin B. Kent" wrote:
>
> > Stuart Smith wrote:
> >
> > > Hi all
> > >
> > > I was wondering if anyone has every wanted to be able to use recursion
> > > in Labview and
if so, how did they solve it?
>
>
>
> >
> > I have always been confused about recursion, that is where a function calls
> > itself right ??
> > I think in order to make this work you would have to make the VI re-entrant
> > (under VI setup->Execution Options select Reentrant Execution).
> > This could be accomplished I believe without doing this , by simply keeping
> > a count of each of the stimuli, external to the function.
>
> It never hurts to check out the NI Web site: a search for "recursive" turned up
> a nice factorial example that uses VI Server and a Call by Reference node to do
> the job. Here's the URL:
>
> http://digital.ni.com/explprog.nsf/websearch/dcce30e278e2cbb88625674b007d45b6
>
> Reentrancy is indeed used. LabVIEW isn't LISP, though, and recursion is pretty
> difficult to achieve as of LabVIEW 5.1. Most (almost all?) LabVIEW tasks are
> probably better done using iterative methods, both in terms of programming
> simplicity and performance.
>
> Regards,
>
John Lum
> National Instruments