Breakout Room 1
There will be prolog questions on the exam. Let¡¯s review a bit.
Write a prolog rule fib/2, so that fib(N,F) generates the fibonacci sequence
N=0, F=1
N=1, F=1,
N=2, F=2, N=3, F=3, N=4, F=5, N=5, F=8, N=6, F=13, ….
The fibonacci sequence is F0=1, F1=1, Fn+1=Fn-1 + Fn
fib(0, F) :- F = 1. fib (1, F) :- F = 1.
fb(1, 1). fb(0, 1). fn(N,F) :-
fb(N2, F2),
N is N2 + 2, N1 is N2 + 1, fb(N1, F1),
F is F1 + F2 ….
Breakout Room 1
There will be prolog questions on the exam. Let¡¯s review a bit.
Write a prolog rule fiblike(F) that is true when F is a list and each item ofFis the sum of the previous two. It should always be true if there are less than three items in the list.
Examples:
fiblike([]) is true.
fiblike([2,3]) is true.
fiblike([2,3,5]) is true.
fiblike([2,3,4]) is false.
fiblike([3,4, 7, 11]) is true.
fiblike([3,4, 7, 10]) is false.
fiblike([]).
fiblike([_]).
fiblike([_, _]).
fiblike([A, B, C | T]): C is A + B, fiblike([B, C | T]).
fib2([]).
fib2([1]).
fib2([1,1|T]) :- fiblike([1, 1 | T]).
Breakout Room 2
There will be prolog questions on the exam. Let¡¯s review a bit.
Write a prolog rule fib/2, so that fib(N,F) generates the fibonacci sequence
N=0, F=1
N=1, F=1,
N=2, F=2, N=3, F=3, N=4, F=5, N=5, F=8, N=6, F=13, ….
The fibonacci sequence is F0=1, F1=1, Fn+1=Fn-1 + Fn
Breakout Room 2
There will be prolog questions on the exam. Let¡¯s review a bit.
Write a prolog rule fiblike(F) that is true when each item of F is the sum of the previous two. It should always be true if there are less than three items in the list.
Examples:
fiblike([]) is true.
fiblike([2,3]) is true.
fiblike([2,3,5]) is true.
fiblike([2,3,4]) is false.
fiblike([3,4, 7, 11]) is true.
fiblike([3,4, 7, 10]) is false.
fiblike([]) :- !. fiblike([_]) :- !. fiblike([_, _]) :- !.
fiblike([N1, N2, N3 | Rest]) :-
N3 is N1 + N2,
append([N2, N3], Rest, NewList), fiblike(NewList).
Group 2
Static: x= 5
Dynamic: x = 10
Group 2
var visibility
d fun3
e fun3
f fun3
c fun2 b fun1 a main
Group 2
var visibility
d fun3
e fun3
f fun3
c fun1 b fun1 a main
Group 2
var visibility B,c,d fun1
E, f fun3 A main
Var visibility b, c, d fun1 e, f fun3 a main
Var visiblity c, d, e fun2
f fun3
b fun1
a main
Group 2
1. A (def1), b c d (def 2)
2. A (def1), b (def 2), c d e (def 3)
3. a(def1), b c d (def 2)
4. A B C (def 1)
Group 2
sub1
X (global), a, y, z (sub1)
sub2
A, b, z (sub2), y (sub1), x (global) sub3
a, x, w (sub3) y, z (global)
a
I. sub1 – uses first instantiation Ii. sub2 – uses first
Iii. sub3 – uses first
B
I. sub1 – uses second instantiation Ii. sub2 – uses second
Iii. sub3 – uses first
Don¡¯t forget the quizzes
¡ñ List 6 attributes of variables
¡ñ List 5 binding times
¡ñ ____ binding happens before we run the program, ___ binding is done when
a program is running
¡ñ A function is ______ when it has a frame on the call stack
¡ñ The ____________ ___________ is the set of all variables visible at a point
in the program.
Don¡¯t forget the quizzes
¡ñ List 6 attributes of variables
¡ð Name, address, type, scope, lifetime, value
¡ñ List 5 binding times (6?)
¡ð Language design, implementation, compile, load, link time, run -time
¡ñ STATIC binding happens before we run the program, DYNAMIC binding is done when a program is running
¡ñ A function is ______ when it has a frame on the call stack
¡ñ The ____________ ___________ is the set of all variables visible at a point
in the program.
That¡¯s it! Thanks!
Call me over if you are done