%% lists.pl %% %% Author(s): %% %% CS 60 Hw 8, part 2 %% %% % some "nice" prolog settings... see assignment % description for the details on what these do % -- but it's not crucial to know the details of these Prolog internals :- set_prolog_flag( prompt_alternatives_on, groundness ). :- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), attributes(portray), max_depth(999), priority(699)]). %% a couple of example predicates that might be helpful... % % member( E, L ) should be true if E is a top-level member of the list L % member should work when E is a variable or bound; L should be bound % member( E, [E|_] ). member( E, [_|R] ) :- member( E, R ). % % reverse( L, Rev ) should be true if Rev is the reverse of the list L % reverse should work when Rev is a variable or bound; L should be bound % reverse( [], [] ). % base case ~ they don't always involve [] in Prolog! reverse( [F|R], Rev ) :- reverse( R, Tmp ), append( Tmp, [F], Rev ). %% Here are commented-out placeholders for this week's predicates... %% Be sure to comment each predicate your write. %% removeOne( E, L, NewL ) %% count( E, L, N ) %% find( Pattern, Target, Index ) %% depth( E, Tree, N ) % a helper predicate to define a tree tree1( [ 42, [ 20, [10, [5, [], []], [18, [], []]], [] ], [ 100, [67, [50, [], []], []], [150, [], [2009, [], []]] ] ] ). %% insert( E, Tree, NewTree ) %% path( A, B, Graph, Path ) % a helper predicate to define a graph graph1( [ [a,b], [b,c], [c,d], [b,w], [w,x], [x,z], [b,z] ] ).