A preview of how to implement a linked-link/tree (hierachical list) in FileMaker 7. This is largely inspired by the excellent Mikhail Indoshin's FileMaker 4/5 techniques. This example isn't the most 'optimized' but it illustrates some of the strengths of FM7 and applies some of cooler features of FileMaker 7.
Excerpt from my post the FSA.Tech.Talk@filemaker.webcrossing.com in response to a thread on script recursion depth:
[BEGIN]
John et al,
Didn't mean to be esoteric about this thread. Your
point is well taken, although contrary to your modesty, your 'handle'
on this matter already appears to be quite thorough. That said, my
question wasn't about memory-management per se; it was about how
FileMaker 7 behaved when scripts called themselves.
Let me be
absolutely clear here. I am talking about SCRIPTS, not about
calculations or custom functions. Two completely separate problems.
You
see, in FM6, has Jason pointed out, there was a limit to how many
"layers" of nested scripts FileMaker can keep in its head before it'd
would simply quit or die ungracefully (aka, crash). I think the number
was 1170 or something like that. I simply wanted to make sure there
weren't any 'hard' limits that FileMaker 7 set for itself.
Why?
Because, it is related to a problem I am working on:
I
have implemented a way to store records that are 'linked' together like
in a tree. You can imagine my data-structure looking like this:
+-A
|--B
| |--I
|--C
| |--D
| +--H
|
+-E
|--F
Imagine
an outliner program (like the excellent OmniOutliner) where you have
nested 'lines' such that A is the parent of B and C; and C is the
parent of D and so forth.
There are numerous reasons why I have
chosen this linked-list/tree approach. I can explore this topic in
further detail elsewhere. But for the sake of discussion, one of the
things I needed was the ability to move an entire branch 'cheaply'.
See, if I want to make A (and all its descendants) a sub-level of
another node, say E, all I have to do make E the parent of A.
Regardless of how many descendants A has, that 'move' is still just a
single operation.
One of the things I want to do is 'walk'
through EVERY descendant of A (children, grandchildren, etc.) and do
something, say, copy the ID of that node to a list at each one.
We can use a recursive script to do this. Here's the English version of the script, WalkTheTree:
WalkTheTree (
Add the record ID of this node to myList
// What i want to do at each step
If I have a Child
Go to Child
Perform script "WalkTheTree" // This is the recursive part, call itself before continuing on.
// Return to Parent node
If I have a Sibling
Go to Sibling
Perform script "WalkTheTree"
End if
)
WARNING:
THIS IS NOT WORKING CODE. I am merely illustrating the essential
concepts of using a script to recursively walk a tree. See how I am
going to each child or sibling and calling the same "WalkTheTree"
script which then goes to its child or sibling and does the same thing
until there are no more child or sibling nodes?
Every time
"WalkTheTree" calls itself, FileMaker is adding the 'new' WalkTheTree'
to its stack of scripts it keeps in its head. Each preceding
"WalkTheTree" script is put on 'hold' (not terminated) until the next
one and the next one after that until there is no more 'next' one is
done. When it reaches the point where it can't go any further (no more
child or sibling), it adds that node's ID to a list, terminates, and
allows its referring script to continue.
The point of all of this is that I want to make sure FileMaker will dutifully walk 'deep' trees without giving up first.
Hence the original question.
[snip]
A point here: A stack is just a method and a place to keep stuff where you put one thing on top of each other as it gets larger. It is actually Last-In, First-Out. The last plate you push in is the first one you take out.
[snip]
Runaway recursions are bad for a variety of reasons including those
you mentioned. The point for me was to make sure my scripts didn't
prematurely quit leaving me with a tree half walked.
Anyway, you
can see a preview (screen shot) of this linked-list/tree approach
implemented as in a hierarchical list here:
http://blinkerfish.blogs.com/digitalsoap/2005/02/linked_listtree.html
[END]


Recent Comments