> I have a tree represented by a list of lists.
> I want to modify any subtree.
> I represent location of the subtree by a path from the root.
>
> eg if path is [2 1 3]
> i want to do
> newsubtree->tree(2)(1)(3);
>
> How can I do this for any tree<path1,path2,...,pathn> ?
You want to define a procedure with three arguments
define update_tree(tree, path, subtree);
The key point to note is that if path is a list of N numbers
[p1 p2 p3 ... pN], the first N-1 numbers are used to select branches
down the tree and the last one updates the pNth branch from the last
selected node.
So just iterate down the path selecting branches till you have only
one number left in the path, in which case you do the update.
You should be able to contstruct the code from that, using the fact that
you have only one item in a list if
tl(list) == []
You might find "for tail on list do ... endfor" useful.
Aaron
|