Skip to content

Instantly share code, notes, and snippets.

@precious
Created December 24, 2012 21:07
Show Gist options
  • Save precious/4370701 to your computer and use it in GitHub Desktop.
Save precious/4370701 to your computer and use it in GitHub Desktop.
children(Parent,L) :- findall(Next,parent(Parent,Next),L).
ancestors(Child,L) :- findall(Next,parent(Next,Child),L).
repr_internal(Elem,L,R) :- (L == [] -> ancestors(Elem,R); children(Elem,R)).
repr_retval(Elem,R) :- children(Elem,L), repr_internal(Elem,L,R).
repr(Elem):- repr_retval(Elem,R), write(R).
read_line_pls(L) :- read_line(X),string_to_atom(X,L).
main :-
nl,
write('Choose action:\n'),
write('1. save current state\n'),
write('2. find element\n'),
write('3. add element\n'),
write('4. remove element\n'),
write('5. exit\n'),
write('>>> '),
readln([X]),
switch(X) ; main.
switch(1):- qsave_program('lab2.out',[class(development),op(save),autoload(true),goal(init)]), main.
switch(2):- write('Type element\'s name: '), read_line_pls(A), repr(A),nl, main.
switch(3):- write('Type parent\'s name: '), read_line_pls(P),
write('Type child\'s name: '), read_line_pls(C),
assert(parent(P,C)), main.
switch(4):- write('Type element\'s name: '), read_line_pls(A), retract(parent(_,A)), main.
switch(5):- write('Bye.\n'), halt, halt.
init :- [library(http/dcg_basics),library(dialect/sicstus)], consult('cityes.pl'), main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment