Programming Languages (CS302 2006S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
Back to Logic Programming (2). On to Haskell (1).
Held: Friday, April 21, 2006
Summary: Today we explore some particular examples in Prolog.
Related Pages:
Due
Assignments
Notes:
Overview:
[XXs]
[X0,X1,X2,X3]
['filename'].
add
predicate
takes three parameters: the first addend, the second addend, and the
result.
A1: add([],X,X). A2: add([1Remaining],Addend,[1PartialResult]) : add(Remaining,Addend,PartialResult).
? add([1,1], [1,1,1], [1,1,1,1,1]) // use A2 with // Remaining0 = [1] // Addend0 = [1,1,1] // PartialResult0 = [1,1,1,1] ? add([1], [1,1,1], [1,1,1,1]) // use A2 with // Remaining0 = [] // Addend0 = [1,1,1] // PartialResult0 = [1,1,1] ? add([], [1,1,1], [1,1,1]) // use A1 with // X0 = [1,1,1] ? // nothing left to prove?
? add(X, [1,1,1], [1,1,1,1,1]). // use A2 with // X = [1Remaining0] // Remaining0 undefined // Addend0 = [1,1,1] // PartialResult0 = [1,1,1,1] ? add(Remaining0, [1,1,1], [1,1,1,1]) // use A2 with // Remaining0 = [1Remaining1] // Remaining1 undefined // Addend1 = [1,1,1] // PartialResult1 = [1,1,1] ? add(Remaining1, [1,1,1], [1,1,1]) // Note A1 and A2 match // use A1 with // Remaining1 = [] // X = [1,1,1] ? // Nothing left // X = [1Remaining0] // Remaining0 = [1Remaining1] // Remaining1 = [] // => [1,1]
le
) predicate?
multiply
predicate?
factorial
predicate?
contains(L,X)
, that determines ifL contains X?
contains
to Write a predicate that determines whether a list is a permutation of the word "ingrate".
x
,
and the binary operations plus
and times
.
plus(plus(times(3,times(x,x)), times(5,x)), 4)
substitute(X, Exp, Result)
, that holds if
Result
is the result of substituting X
for each x
in Exp
.
Back to Logic Programming (2). On to Haskell (1).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 10 09:03:03 2006.
The source to the document was last modified on Thu Jan 12 09:00:38 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2006S/Outlines/outline.33.html
.
You may wish to validate this document's HTML ; ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu