users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dynamic Allocation seems to crash gprolog


From: Leonardo B. Lopes
Subject: Dynamic Allocation seems to crash gprolog
Date: Thu, 13 Dec 2001 21:44:44 -0600 (CST)

Dear Friends:

        I have this little routine which does a search over special trees.
I would like to delete the tree once it is no longer useful, but this code
seems to crash gprolog. Is there something I'm doing wrong?

:- dynamic(parent/2,root/1,is_parent/2,is_root/1).

:- op(500,xfx,(is_parent)). 

:- op(500,xfx,'has_children'). 
X has_children 0 :-     leaf(X).
X has_children Y :- setof(Children, X is_parent Children, Set),
                                        length(Set,Y).

printTree(X) :- write('$'),
                                C areChildrenOf X,
                                printChildren(C),
                                write('^').

createBalancedTree([],_):- !.
createBalancedTree([RootDegree|DegreeList],Tree) :-
        new_atom(Tree),
        for(_,1,RootDegree),
                createBalancedTree(DegreeList,Child),
                asserta( Tree is_parent Child),
        Tree has_children RootDegree.
        
deleteTree(Tree) :-
        Tree is_parent X,
        retract(Tree is_parent X),
        deleteTree(X).

Also, any other trees previously defined also get deleted when I use
deleteTree. BTW, I'm using gprolog 1.2.1.

Appreciate any help!
Leo.

========================================================================
Leonardo B. Lopes                                       address@hidden 
Ph.D. Student                                              (847)491-8470
IEMS - Northwestern University              http://www.iems.nwu.edu/~leo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]