[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Back to Prolog. On to Languages and Grammars.
Held Monday, April 5
Summary
Contents
Notes
concatenate.
concatenate(Xs,Ys,Zs) holds when Zs is the
list created by concatenating Xs and Ys.
concat([],Ys,Ys).
concat([X|Xs], Ys, [X|Whatever]) :- concat(Xs,Ys,Whatever).
?- concat([a,b,c], [d,e,f], [a,b,c,d,e,f]). yes
?- concat([a,b,c], [d,e,f], L). L=[a,b,c,d,e,f] yes
?- concat([a,b,c], X, [a,b,c,d,e,f]). X=[d,e,f] yes ?- concat(X, [d,e,f], [a,b,c,d,e,f]). X=[a,b,c] yes
?- concat(Xs, Ys, [a,b,c,d,e,f]).
member.
member might even be able
to extract the members of a list.
display).
write(X) predicate always holds and has the side effect
of writing its argument to stdout.
nl predicate always holds and has the side effect
of writing a newline to stdout.
in_tree function to list the nodes
it looks at, we might write:
showpath(Val,empty) :- write("not found!"), nl, fail.
showpath(Val,node(Val,Less,Greater)) :-
write(Val), nl.
showpath(Val,node(NodeVal,Less,Greater)) :-
Val < NodeVal, write(NodeVal), nl, showpath(Val,Less).
showpath(Val,node(NodeVal,Less,Greater)) :-
Val > NodeVal, write(NodeVal), nl, showpath(Val,Greater).
node and
empty to define trees.
inTree(Val,empty) :- fail. inTree(Val,node(Val,Less,Greater)). inTree(Val,node(NodeVal,Less,Greater)) :- Val < NodeVal, in_tree(Val,Less). inTree(Val,node(NodeVal,Less,Greater)) :- Val > NodeVal, in_tree(Val,Greater).
insert and delete.
History
Back to Prolog. On to Languages and Grammars.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Disclaimer Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Outlines/outline.25.html
Source text last modified Mon Apr 5 14:31:06 1999.
This page generated on Mon Apr 5 14:37:55 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu