Frequently Asked Questions
Q: How to submit assignments?
A: Assignments should be submitted by email with attachments. The
format should be PDF or TXT for descriptive questions. Answers with
source code should be submitted as .lsp or .pl files. You should
embed your descriptions as comments in the source code. Drawings can
be done by hand and handed in. There should be one document per
question, for example assignment #1 can be 3 documents or just 2
documents and a hand drawing.
Q: What are some of the valid inputs to
the InnerProduct2 functional in Assignment #2 Question #4?
A: There can be any number of layers in the list, so the following
are valid:
((1 2 3) 2 3)
((6 7 8) 7 8)
)
and
(
((1 2 3) 2 (3 4
5))
((6 7 8) 7 (7 8
9))
)
and
((1 (2 2 3) 3) 2
(3 4 5))
((6 (3 3 7) 8) 7
(7 8 9))
)
Q: Tip for Question
#3 of assignment #4.
How can I retrieve values from rule parsing?
A: Here is an example code that can query for field names of
some database table.
:-op(800,xfx,isAFieldOf).
:-op(800,xf,isATable).
emplyee isATable.
lastName isAFieldOf employee.
firstName isAFieldOf employee.
dateOfBirth isAFieldOf employee.
/*
[is,X,a,field,of,Y,?]
*/
q1 --> [is],token(X),[a,field,of],token(Y),[?],{X isAFieldOf Y}.
token(X,[X|ToDo],ToDo).
/*
?- q1([is,X,a,field,of,Y,?],[]).
X = lastName,
Y = employee ;
X = firstName,
Y = employee ;
X = dateOfBirth,
Y = employee.
?- bagof(X,q1([is,X,a,field,of,Y,?],[]),B).
Y = employee,
B = [lastName, firstName, dateOfBirth].
Notice that we can get the list of all alternatives by wrapping
bagof around our goal. First provide the variable to test for
alternatives, then the goal and lastly the list with the
alternatives.
*/
q2(F) --> [what,are,the,fields,of,the],token(Y),[table,?],{bagof(X,
X isAFieldOf Y,F)}.
/*
?- q2(F,[what,are,the,fields,of,the,employee,table,?],[]).
F = [lastName, firstName, dateOfBirth].
*/
Q: What are some of the valid inputs to
the question #1 and #2 in Assignment #4?
A: !!! make sure the predicate will not go into infinite loop if
alternatives are asked but no more are found !!!
Q1 basic mark:
factorialExt(10,120).
factorialExt(5,120).
factorialExt(7,F).
factorialExt(N,120).
factorialExt(-1,X).
factorialExt(a,X).
factorialExt(1.1,X).
Q1 top mark if:
factorialExt(N,F).
Q2 basic mark:
everyNth(3,[a,b,c,d,e,f],B).
everyNth(a,B,[a,b,c,d,e,f]).
everyNth(0,B,[a,b,c,d,e,f]).
everyNth(-2,B,[a,b,c,d,e,f]).
everyNth(1.1,B,[a,b,c,d,e,f]).
everyNth(3,a,X).
everyNth(3,Z,b).
Q2 top mark if some of:
everyNth(3,B,C).
everyNth(N,[a,b,c,d,e,f],X).
everyNth(N,X,[a,b,c,d,e,f]).
Q: How can I eliminate the "No
permission to modify static_procedure ..." error when asserting new
facts in_question #3 in Assignment #4?
A: Add the following 2 lines at the top of your prolog program:
:-dynamic isA/2.
:-dynamic isIn/2.
:-dynamic populationIs/2.