I’ve somewhat avoided recursive scripts, so far I’ve been able to make use of a 
custom function when I need a recursive function. When I use a recursive custom 
function, I’m usually building something, like a list. I guess I always use 
parameters when passing values to a function, and not variables really.

 

I notice that no matter what I’m doing, my recursive functions usually end up 
with 3 parameters; input, operator, and output. I call it with the output 
parameter blank, like: CustomFunction( biglist; dothis; “”)

 

within the custom function, it’s basically a glorified IF statement: 

If (there is still some input), 

  then CustomFunction( input – this iteration’s value; operator; output + this 
iteration’s value)

else

  return output

end

 

It was me wrapping my head around the fact that I needed that extra parameter 
to hold what I’m working on that allowed me to make good use of recursive 
custom functions. I’m not sure that this helps you at all, but hopefully 
doesn’t hurt.

 

Geoff

 

From: FileMaker Pro Discussions [mailto:[email protected]] On 
Behalf Of Jason Bourque
Sent: Tuesday, March 22, 2011 2:38 PM
To: [email protected]
Subject: Script Recursion Best Practice

 

Hello,

I have a project database where each project has tasks. Some of those tasks 
point back to a project that ha s tasks and again some of those tasks point 
back to Projects which have tasks. This allows me to use multiple tasks across 
projects and only have to update one task and all of the associated projects 
update.
 
What I want to do is print out all tasks from every project in this relation. 
So how should I handle this?

I have a printing table and a script that loops through the projects task 
bringing over task specifics in order. 

I  tried a recursive script with global variables that have multiple fields so 
as the scripts call themselves the level indication increases or decreases to 
keep in sync with the correct project and it's tasks.
 
I read where functions can be recursive. How would I use th e function to do 
this?

I have done recursion  in Applescript. But the global variables don't seem to 
work the same way.

Any help is greatly appreciated.

Thank You,

Jason Bourque

Reply via email to