Professional Documents
Culture Documents
Programming Paradigms
1
• Course overview
• Introduction to programming
paradigms
• Review: The object-oriented
Topics paradigm in Java
• Imperative and concurrent
programming paradigm: Go.
• Logic paradigm: Prolog.
• Functional paradigm: Scheme.
• Assignments due date extended
Announcement to March 5th
• Thursday March 4 (4:00 -5:20
Announcement pm) live Tutorial session for
assignment 1 go practice exam
The slides posted through the term are based of the
slides offered by:
Prof. Robert Laganiere
Prof. Jochen Lang
Acknowledgment Demo code:
https://www.site.uottawa.ca/~jl
ang/CSI2120/demoCode.html
Logic Programming in Prolog
• List Representations
– dot operator
– Trees and Vine diagrams
• More List Processing
– Insertion vs. Deletion
– List processing
• Double Recursion
• Accumulators
– Examples
List Representations
• Examples: .
.
pie .
X Y
fruit .
cream nil
Fundamental List Properties
• A list is represented by a particular tree with all the leaves
of the tree on branches to the left.
– Sometimes the tree is shown in a vine diagram
. . . nil
nil
1 2 3
a
Fundamental List Properties (cont’d)
• Recursive sorting
• Quicksort with simply selecting the first element as the
pivot, better to randomize
sortList([],[]).
sortList([P|Q],T) :- partitionList(P,Q,G,D)
sortList(G,GG),
sortList(D,DD),
append(GG,[P|DD],T).
– Making use of the library predicate append (could
use our own definition appendList from before).
– Needs partitionList predicate (next slide).
Partitioning a List
?- mirror(L,[1,2,3,4]).
L= [4,3,2,1].
Improved List Inversion
reverseList([],L,L) :- !.
reverseList([H|T],L,R) :-
reverseList(T,[H|L],R).
mirrorAcc(L,R) :- reverseList(L,[],R).
• List Representations
– dot operator
– Trees and Vine diagrams
• More List Processing
– Insertion vs. Deletion
– List processing
• Double Recursion
• Accumulators
– Examples