CSCI 461 - Quiz 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following defines a macro for the C language? MIN(X,Y) ((X) < (Y) ? (X) : (Y)) # MIN(X,Y) ((X) < (Y) ? (X) : (Y)) define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))

#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))

Any term can appear in a query, including variables TRUE FALSE

TRUE

Most General Unifier is unique up to variable renaming TRUE FALSE

TRUE

The activation record for the following function can be deallocated as soon as the function returns. fun f x = x+1; TRUE FALSE

TRUE

The natural implementation of Pass By Value is to use textual substitution before compiling TRUE FALSE

TRUE

The parameters passed at the point of function call are called actual parameters. TRUE FALSE

TRUE

The predicate assert(X) adds the term X as a fact in the database. TRUE FALSE

TRUE

Consider the following grammar, <exp> ::= <exp> + <mulexp> | <mulexp> <mulexp> ::= <mulexp> * <rootexp> | <rootexp> <rootexp> ::= (<exp>) | <constant> which of the following is true? The grammar is ambiguous The operators are left associative + has higher precedence There is an error in the grammar

The operators are left associative

A few languages, including C, C++, and most of the scripting languages like JavaScript, Python, and Perl, allow actual parameter lists of any length True False

True

A proof tree contains two kinds of nodes, called nothing nodes and solve nodes. True False

True

Atoms are not variables True False

True

Given fact s. If we cannot unify s with a goal G, then the goal G cannot be proved by using s True False

True

In java, when the value of the parameter is a reference, the actual parameter cannot be changed by called method, however, the object referred by the actual parameter can be changed. True False

True

In static allocation of activation records, the location of activation record was determined before runtime True False

True

Object-oriented languages use variables whose lifetimes are associated with object lifetimes True False

True

Preducates +, -, *, and / are operators with usual precedence and associativities True False

True

Prolog chooses unifiers that do just enough substitution to unify, and no more. That is, it chooses the MGU—the Most General Unifier True False

True

The activation record for the following function can be deallocated as soon as the function returns. fun f x = fn y => y + 1; True False

True

The activation record for the following function can be deallocated as soon as the function returns. fun f x = map ~ x; True False

True

The following C++ definition int f(int a = 1, int b = 2, int c = 3){} allows the caller to provide 0, 1, 2, or 3 actual parameters True False

True

The formal parameter is an alias for the actual parameter -- another name for the same memory location True False

True

The natural implementation of Macro Expansion is to use textual substitution before compiling True False

True

The result of a query is either true or false True False

True

The simplest thing in Prolog database is fact: A term followed by period. True False

True

When parameters are passed by value, changes to a formal parameter do not affect the actual parameter True False

True

What is the result of the following? ?- sort ([4, 2, 3, 1], Y).

Y = [1, 2, 3, 4]

What is the result of the following? ?- reverse ([1, 2, 3, 4], Y).

Y=[4,3,2,1]

The following ML function contains a function call that passes a function parameter f. In each case, will the function f use its nesting link when it is called. fun addall y theList = let fun f x = x + y; in map f theList end; Yes No Cannot determine The function has an error

Yes

Which is not a result of the following? ?- select (2, Y, [1, 3]). [1, 2, 3] [2, 1, 3] [3, 2, 1] [1, 3, 2]

[3, 2, 1]

What is the output of the following in SWI-Prolog? append(X, Y, [1, 2]), print(X), print(' '), nl, X=Y. []' '[1,2] [1]' '[2] [1,2]' '[] false.

[]' '[1,2]

Given this list of goal terms:[p(X),s(X)] And this rule to apply: p(f(Y)) :- q(Y), r(Y). The MGU of the heads is {X -> f(Y)}, then resolution([p(f(Y)),q(Y),r(Y)], [p(X),s(X)])= [r(Y),s(f(Y))] [q(Y),s(f(Y))] [q(Y),r(Y),s(f(Y))] [s(f(Y))]

[q(Y),r(Y),s(f(Y))]

To use textual substitution before compiling is a natural implementation of ________________ pass by value pass by name pass by Macro expansion pass by reference

pass by Macro expansion

Which of the following is also called copy-in/copy-out? pass by value pass by result pass by value result pass by reference

pass by value result

Which of the following ends a conjunctive query? commas semicolons questions marks periods

periods

Which of the following is true about Prolog list? predicate . is equilvalent to :: in ML append can be used with variable in any position append is a user defined predicate for list [ ] represent empty list

predicate . is equilvalent to :: in ML [ ] represent empty list

Consider the following formal semantic: Which of the following is a Prolog Implementation of this semantic? val1(plus(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), val1(pluss(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue + YValue. val1(plus(X,Y),Value) :- value = X + Y val1(pluss(X,Y),Value) :- Value is X * Y.

val1(pluss(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue + YValue.

parent(adam,Child) and parent(adam,seth) __________ by binding the variable Child to the atom seth

unify

Consider the following grammar, <exp> ::= <exp> + <mulexp> | <mulexp> <mulexp> ::= <mulexp> * <rootexp> | <rootexp> <rootexp> ::= (<exp>) | <constant> which of the following is true? The grammar is umbiguous The operators are right associative * has higher precedence There is an error in the grammar

* has higher precedence

What is the output of the following program? member(X, [a, b, c]), print(X), !. 1 1 2 Error 1 2 3

1

Given function int plus(int a, int b){ return a+b; } and function call int x = plus(1, 2). Which of the following are actual parameters? a b 1 2

1 2

Suppose that the Prolog interpreter use the following solve algorithm function solve(goals) if goals is empty then succeed() else for each clause c in the program, in order if head(c) does not unify with head(goals) then do nothing else solve(resolution(c, goals)) Given the following program, 1. p(f(Y)) :- q(Y),r(Y). 2. q(g(Z)). 3. q(h(Z)). 4. r(h(a)). When it recursively call solve([r(h(Z))]), which of clause do nothing? 1 2 3 4

1 2 3

Consider the following functions, with a fictitious keyword by-value-result, so the parameter c in function plus is passed by-value-result. When we call f(), what will be the value of x in the activation record of f? Void plus (int a, by-value-result int b) { b+= a; } void f() { int x = 3; plus(4, x); } 3 7 4 Unknown

7

Suppose that the Prolog interpreter use the following solve algorithm function solve(goals) if goals is empty then succeed() else for each clause c in the program, in order if head(c) does not unify with head(goals) then do nothing else solve(resolution(c, goals)) Given the following program, 1. p(f(Y)) :- q(Y),r(Y). 2. q(g(Z)). 3. q(h(Z)). 4. r(h(a)). For which clause, the call solve([P(X)]) will do nothing (not consider any thing possible happen in ne recursive call yet)? 1 2 3 4

2 3 4

Consider the following functions, with a fictitious keyword by-result, so the parameter c in function plus is passed by-result. When we call f(), what will be the value of z in the activation record of f? void plus(int a, int b, by-result int c) { c = a+b; } void f() { int x = 3; int y = 4; int z; plus(x, y, z); } Unknown 4 7 3

7

Which of the following defines a <rule>? := <fact> | <rule> ::= <term> . ::= <term> :- <termlist>. ::= <term> | <term> , <termlist>

::= <term> :- <termlist>.

Which of the following defines <compound-term> ::= <integer> | <real number> | <atom> := <constant> | <variable> | <compound-term> ::= <term> | <term> , <termlist> := <atom> ( <termlist> )

:= <atom> ( <termlist> )

Entering a _____________ makes the Prolog system continues to search when it runs a query ; . ? ,

;

Which of the following are true? A query can only be in one line A query ends with a period A query ends with a semi colon A query can have multiple lines

A query ends with a period A query can have multiple lines

The following ML function contains a function call that passes a function parameter f. In each case, will the function f use its nesting link when it is called. fun do123 f = map f [1, 2, 3]; Yes No Cannot determine. Need know the definition of f. The function has an error

Cannot determine. Need know the definition of f.

The following ML function contains a function call that passes a function parameter f. In each case, will the function f use its nesting link when it is called. fun haveFun f = map f [1, 2, 3, 4, 5, 6]; No The function has an error Yes Cannot determine. Need know the definition of f.

Cannot determine. Need know the definition of f.

Prolog must find successes in the proof tree order, which is defined as following: Given a program and a query, a Prolog language system must act in the order given by a _____-first, __________________ traversal of the proof tree depth, left-to-right depth, right-to-left breadth, left-to-right breadth, right-to-left

depth, left-to-right

Check all correct statement about the activation record. Dynamic allocation means that activation record allocated when function is called In a stack of activation records: stack frames pushed on call, popped on return To support recursion, we need to allocate a new activation record for each activation In C, it can be deallocated when the function returns

Dynamic allocation means that activation record allocated when function is called In a stack of activation records: stack frames pushed on call, popped on return To support recursion, we need to allocate a new activation record for each activation In C, it can be deallocated when the function returns

In dynamic allocation of activation records, the location of activation record was determined before runtime TRUE FALSE

FALSE

Each nothing node in a proof tree is an internal node True False

False

The activation record for the following function can be deallocated as soon as the function returns. fun f x = fn y => x+y; True False

False

The parameters passed at the point of function call are called formal parameters. True False

False

When two expression have the same rvalue, they are aliases of each other True False

False

fun fact n = if (n=0) then 1 else let val b = fact (n-1) in n*b end; The variable b is activation specific to the whole fact function. True False

False

X and f(a,X) do unify by {X -> f(a,X)} True False

Falsee

Check all correct statement about the activation record. In a stack of activation records: stack frames pushed on call, popped on return In C, it can be deallocated when the function returns Dynamic allocation means that activation record allocated when function is called To support recursion, we need to allocate a new activation record for each activation

In a stack of activation records: stack frames pushed on call, popped on return In C, it can be deallocated when the function returns Dynamic allocation means that activation record allocated when function is called To support recursion, we need to allocate a new activation record for each activation

The following ML function contains a function call that passes a function parameter f. In each case, will the function f use its nesting link when it is called. fun tripleall theList = let fun f x = x * 3; in map f theList end;

No

Which of the following unify? a(X,X,b) and a(b,X,X) f(X,b) and f(a,Y) f(X,b) and g(X,b) a and b

a(X,X,b) and a(b,X,X) f(X,b) and f(a,Y)

Given the following C++ definition int f(int a = 1, int b = 2, int c = 3){}, in the function call f(4), which of the following are true about the formal parameter a, b, and c? a=4 b=2 c=3 there is an error

a=4 b=2 c=3

The lifetime of one execution of a function, from call to corresponding return, is called an ____________ of the function assemble action asset activation

activation

Consider the following code: fun addXToAll (x,theList) = let fun addX y = y + x; in map addX theList end; What this function does? add x to y add x to every element in theList append x to theList add x to the last element in theList

add x to every element in theList

Consider the following code: fun addXToAll (x,theList) = let fun addX y = y + x; in map addX theList end; Which function refers to variable x? map addX addXToAll

addX

Consider the following code: fun addXToAll (x,theList) = let fun addX y = y + x; in map addX theList end; Which function calls map? map addX addXToAll

addXToAll

Which of the following parameter passing method(s) is(are) used in Java? by value by reference by result by value-result

by value

Which of the following separate the query terms in a conjunctive query? periods semicolons commas questions marks

commas

In Prolog database, a term followed by a period is called _________________ fact term list rule statement

fact

Consider the simple rule: p :- q, r. To prove a goal via this rule, which of the following are included in the steps of proof? prove q prove r unify goal with q and r unify the goal with p

prove q prove r unify the goal with p

parent(adam, Child) and parent(adam, seth) unify by binding the variable Child to atom ________

seth

Which of the following is not a term kind in Prolog? Compounded terms constants variables strings

strings

Two terms ___________ if there is some way of binding their variables that makes them identical unify equal identify are the same

unify

Consider the following formal semantic: <E₁,C>→v₁,<E₂,C>→v₂ --------------------- <plus(E₁,E₂),C>→v₁+v₂ Which of the following is a Prolog Implementation of this semantic? val2(plus(X,Y),Context,Value) :- val2(X,Context,XValue), val2(Y,Context,YValue), Value is XValue + YValue. val2(var(X),Context,Value) :- lookup(X,Context,Value). val1(plus(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), val1(pluss(X,Y),Value) :- Value is X * Y. val1(plus(X,Y),Value) :- value = X + Y

val2(plus(X,Y),Context,Value) :- val2(X,Context,XValue), val2(Y,Context,YValue), Value is XValue + YValue. val2(var(X),Context,Value) :- lookup(X,Context,Value).

Consider the following formal semantic: <E₁,C>→v₁,<E₂,C>→v₂ --------------------- <times(E₁,E₂),C>→v₁+v₂ Which of the following is a Prolog Implementation of this semantic? val1(times(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), val2(times(X,Y),Context,Value) :- val2(X,Context,XValue), val2(Y,Context,YValue), Value is XValue + YValue. val2(var(X),Context,Value) :- lookup(X,Context,Value). val1(times(X,Y),Value) :- value = X * Y val1(times(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue * YValue.

val2(times(X,Y),Context,Value) :- val2(X,Context,XValue), val2(Y,Context,YValue), Value is XValue + YValue. val2(var(X),Context,Value) :- lookup(X,Context,Value).

Which of the following is NOT a Prolog constant? variable term real number integer

variable

Which of the following for SWI-Prolog to prompt the input? - |: | :

|:


Conjuntos de estudio relacionados

Primary Care and Wellness Ch. 21, 22 and 23

View Set

EAQs 6-10 Psychological Disorders

View Set

macroeconomics practice exam 1- belmont university: CANNONIER

View Set

Development of the UK Constitution

View Set

California: Real Estate Principles - Chapter 24

View Set