2007/2/28, minh thu <[EMAIL PROTECTED]>:
Hi,
I'd like to do something that I thought would be very easy to do with
Scheme but I'm getting lost.
I want to have a global *TREE* symbol to hold nested list. (Each node
is either a string or a list of node, but in this mail I make the
description
with only lists) Initially it is (define *tree* '()), the empty tree.
If I push a node, it becomes '(()).
Now the fun part. I want to keep track of the current (or selected)
node. Initially there's no node, after a first push, the current node
is the inner list.
I want to be able to add a node to the left or to the right of the
current node. Also,
I want to be able to swap two nodes, or push a node outside of its
parent....
Now, I take the fisrt case : adding a node to the left of the current one.
To do this, I need to SET! its parent. But of course I've no pointer
to its parent.
So what I've done is to use a *ACCESS-LIST* which contains a list of
'CAR, 'CDR, ... to have the path from the root to the selected node.
Then I can access the current node with
(define (current-node)
((apply compose (map eval *access-list*)) *tree*)
(I use a list of symbol because it's niser when printed than <procedures>)
Similarly, I've defined a PARENT-NODE procedure (just drop-right the
last element of the acces list).
The problem is I can't SET! (PARENT-NODE).
Do you have an idea about how can I manage this ? I guess there's an
elegant way to write tree editing code but I don't see.
Thanks,
thu
Instead of using a SET! at the top, I think I will try a recursive
porcedure on both the tree and the access-list, and then use a SET! a
the place I need.
Anyway, I'm interested in hearing your ideas.
Thu
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users