[olug] [OT] Of parents and children

Jay Hannah jay at jays.net
Wed Mar 2 19:04:38 UTC 2005


(see OLUG thread for discussion to date)

On Feb 24, 2005, at 10:48 AM, Kevin Lanik wrote:
> Slightly off topic, but an interesting programming problem here. I'm
> programming in objective-c (language doesn't matter much though) and I
> basically have a tree. My problem is that I'd like to be able to take
> a node and move it into one of it's children (or, since there is X
> level of depth) or somewhere in it's own lineage. It's been decided to
> preserve as much hierarchy as possible, so if a node moves to it's
> subnode it retains its children. For example, node 1's parent is the
> root node: it has children 2 and 3. 2 has children 4 and 5. I want to
> move node 1 into node 4's list. The first of two scenarios now is that
> node 2's parent becomes the root node and node 1's parent  becomes
> node 4, all other nodes stay the same. The other scenario makes node
> 4's parent the root node and node 1's parent 4, with all other nodes
> retaining thier parents. Does this make sense? The current solution is
> that we don't allow a node to be dropped in one of its children (or
> down the line) but would choosing one of these two be more appropriate
> than the other? I know this isn't exactly the forum for the question,
> but who doesn't enjoy a puzzler!

When you get to actually implementing and persisting a solution I'd use  
OO Perl (I'm biased), or I'd jump into declaritive programming and try  
my hand at prolog (for the logic engine, at least):

http://www.augustana.ca/~mohrj/courses/common/csc370/lecture_notes/ 
prolog2.html?presentation

mmmmm... Prolog... AI... ggrggrllgggghh...

(also see Perl/CPAN's AI::Prolog for the merger of both worlds. -grin-)

j
Omaha Perl Mongers: http://omaha.pm.org




More information about the OLUG mailing list