taylor (05/08/83)
Relay-Version:version B 3/9/83; site harpo.UUCP Message-ID:<175@sdcsvax.UUCP> Date:Sat, 7-May-83 17:15:19 EDT % Some Prolog Utilities % Written by Dave Taylor % push(Item) and pop(Item) allow you to use a FIFO stack. % clear_stack clears the stack. (always returns true) clear_stack :- retract(stack(_)). clear_stack. push(Item) :- retract(stack(Stack)), assert(stack([Item, ..Stack])). push(Item) :- assert(stack([Item])). pop(Item) :- retract(stack([Item, ..Stack])), assert(stack(Stack)). pop(_) :- print('nothing in stack to pop!!'). % get_last(List, Last) substantiates Last to be the last element in List. get_last([Last], Last). get_last([_, ..List], Last) :- get_last(List, Last). % member_of(Atom, List) returns true iff Atom is contained within List. member_of(Item, [Item, ..List]). member_of(Item, [Head, ..List]) :- member_of(Item, List). % share_member(List1, List2) returns true iff the intersection of the % two lists is non-null. share_member([Head, ..List1], List2) :- member_of(Head, List2). share_member([Head, ..List1], List2) :- share_member(List1, List2).