Programming Languages Final Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following is a legal type conversion in Java? A. Double x; x = (double) 2; B. Int x; x = 2.0; C. Double x; x = 2;

A

Which of the following unify? A. A(X,X,b) and a(b,XX) B. F(X,b) and f(a,Y) C. A and b D. F(X, b) and g(X, b)

A b

In Windows, the libraries of functions for delayed linking are store in file with special names that end with ______, an abbreviation for dynamic-link library.

.dll

Consider following code: Fun addXtoAll(X, theList) = Let Fun addX y = y + x; In Map addX the list End; Which function calls addX? A. Map B. AddX C. AddXToAll

A

Namespace in C++ is called: A. Namespace B. Package C. File D. Directory

A

The following ML function contains a function call that passes a function parameter f. In each case, will 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; A. Yes B. No C. Cannot determine D. The function has an error

A

What is the output of the following? Ord # "a"; A. Val it = 97 : int B. Val it = 95 : int C. Val it = 67 : int D. Val it = 65 : int

A

What is the output? Folds (op +) 0 [1,2,3,4]; A. Val it = 10 : int B. Error C. Val it = [1, 2,3,4] : int list

A

What is the result of the following? ?- not(member(1, [1, 2, 3])). A. False B. Error C. True.

A

Which of the following defines a <clause>? A. ::= <fact> | <rule> B. ::= <term>. C. ::= <term> :- <termlist>. D. ::= <term> | <term>, <termlist>

A

Which of the following is not a part of a grammar? A. The set of procedures B. The set of non-terminal symbols C. The start symbol D. The set of tokens

A

Which of the following of a production means that the something inside can be repeated any number of times (zero or more)? A. { something } B. <something> C. [something] D. (Something)

A

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? A. Unify the goal with p B. Unify goal with q and r C. Prove r D. Prove q

A C D

Select all suitable words to fill in the blank of the following scenario: When each activation has its own binding of a variable to a memory location, it is an _______ variable A. Dynamic B. Activation specific C. Static D. Automatic

A b d

Which of the following are the operators in ML? A. ~ B. Andelse C. ^ D. Orelse

A b d

What is the output of the following in ML? Val x = 1 + 2.0 * 3? A. Val x = 7.0 : double B. Error C. Val x = 7.0 : real D. Val x = 7 : int

B

What is the result of the following predicate? ?- 7 = 1 + 2 * 3. A. True B. False

B

What is the result of the following? Set Val x = 1 Val y = 2 in x + y end; A. Val it = 2 : int B. Error. C. Val it = 1 : int D. Val it = 3 : int

B

Which of the following is a correct way to define an enumeration in C? A. Enum day = M | Tu | W | Th | F | Sa | Su; B. Enum day = {M, Tu, W, Th, F, Sa, Su}; C. Datatype day = M | Tu | W | Th | F | Sa | Su; D. Type Day is { M, Tu, W, Th, F, Sa, Su};

B

Which of the following is equivalent to fun f a = fn b +> a + b; A. Fun f(a b) = a+ b; B. Fun f(a, b) = a + b; C. Fun f a b = a + b; D. Fun f a, b = a + b;

B C

Which two addresses are important when the function returns? A. The address of main function B. The address of the activation records that function was using C. The address of the called function D. The address of the machine code to return to in the calling function

B d

Consider the following code. What kind of polymorphism function g present? Class Car { void brake( ) { .... } } Class ManualCar extends Car { void clutch( ) {.... } } Void g(Car z) [ z.brake( ); } Void f(Car x, ManualCar y) {g(x); g(y); } A. Coercion B. Parametric C. Subtype D. Assignment

C

Consider the following halve function: Fun halve nil = (nil, nil) | halve [a] = ([a], nil) | halve (a::b::cs) = Let Val(x,y) = halve cs In (A::x, b::y) End; What is the result of the following statement? Halve[1,2,3,4,5,6,7]; A. Val it = ([1,2,3], [4,5,6,7]) : int list * int list B. Val it = ([1,2,3,4], [5,6,7]) : int list * Int list C. Val it = ([1,3,5,7], [2,4,6]) : int list * int list D. Val it = ([1,3,5,7], [2,4,6]) : list * list

C

Given the following function: fun f(a : char, b : char) = ( a >= b); Which is true? A) f("A", "A"); B) f(#"A", #"a"); C) f(#"A", #"A"); D) f("A", "a");

C

In Prolog database, a term followed by a period is called ___________. A. Statement B. Rule C. Fact D. Term list

C

Prolog must find successes in the proof tree order, which is defined as the following: Given a program and a query, a Prolog lang system must act in the order given by a _________ -first, ____________ traversal of the proof tree. A. Breadth, left to right B. Breadth, right to left C. Depth, left to right D. Depth, right to left

C

The question: whether a given occurrence of a name is in the scope of a given definition? If the question is answered at run time, it is called _______ scoping. A. Traditional B. Static C. Dynamic D. Systematic

C

The term late binding is another way of saying ___________ binding. A. Compiling time B. Coding time C. Running time

C

To use textual substitution before compiling is a natural implementation of __________ A. Pass by reference B. Pass by name C. Pass by Macro expansion D. Pass by value

C

What is the output of the folllowing in ML? "Abcd" >= "abd"; A. Error B. Val it = true : bool C. Val it = false : bool D. Val it = true : boolean

C

What is the output of the following Map (op +) [(1,2), {3,4), (5,6)]; A. Val it = [9, 12] : int list B. Error C. Val it = [3, 7 , 11] : int list D. Val it = [3, 7, 11] : int * int * int

C

What is the output of the following in ML? 1 < 2 also 3 > 4; A. True : Boolean B. True : bool C. Error D. False : boolean

C

What is the output of the following? 1 @ { 2, 3, 4, 5]; A. [1, 2, 3, 4, 5] : int list B. [1, 2, 4, 5] : int list C. Error D. [1, 2, 3, 3, 4, 5] : int list

C

What order the following function has? Int -> bool -> real -> string A. 1 B. 4 C. 3 D. 2

C

Which of the following is a type constructor? Data type exint = Value of int | PlusInf | MinusInf; A. PlusInf B. Value C. Exint D. MinusInf

C

Which of the following is also called copy-in/copy-out? A. Pass by value B. Pass by result C. Pas by value result D. Pass by reference

C

Which of the following is prefix notation? A. A b + B. (A + b == 2)? X : y; C. + a b D. A + b

C

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. A B. B C. 1 D. 2

C d

Consider the following code line Datatype intlist = INTNIL | INTCONS of int * intlist; Which of the following has error? A. INTNIL; B. INTCONS(1, INTNIL); C. INTCONS(1, INTCONS(2, INTNIL); D. INTCONS(1, nil);

D

Give the ML type corresponding to the following set: {true, false} —> {true, false} A. Boolean -> Boolean B. Boolean C. Bool D. Bool -> bool

D

In java, which of the following operator has the highest precedence? A. Subtraction B. * C. Addition D. Negation

D

The job of a __________ is to collect and combine all the different parts of the program. A. Loader B. Editor C. Compiler D. Linker

D

What is the binding time for the following in C or C++? The location in memory of a global static variable. A. Runtime B. Language implementation time C. Language definition time D. Load time

D

What is the result of the following in ML? True andalso 1 div 0 = 0; A. True : bool B. Error because there is sno operator named andalso C. False : bool D. Exception because of div by 0

D

What is the type of the following result? [(1, 2), (1, 3)]; A. (Int X int) list B. Int list C. Int * int D. (Int * int) list

D

What will happen if run the following line in ML? Val real = 3; A. Error. Keyword real cannot be variable name B. Result: Val real = 3 : real C. Result: Val it = 3 : int D. Result: Val real = 3 : int

D

Which of the following is a Prolog implementation of this semantic? D. Val1(times(X,Y), VAlue) :- value = X * Y

D

Which of the following is not a term kind in Prolog? A. Compounded term B. Constants C. Variables D. Strings

D

To avoid ambiguous, there is only one definition for a given name. T F

F

An ML program can tell how the tuple is represented in memory. T/F

False

Just like in C++, bool is a primitive type in ML. T/F

False

Just like in many other languages, ML case construct only compare with constants. T/F

False

To avoid ambiguous, there is only one definition for a given name. T/F

False

Using fn, we get an expression whose value is a named function. T/F

False

When parameters are passed by value, the called method cannot make any changes that are visible to the caller T/F

False

The ___________ a of a programming language defines what the program's behavior and meaning is

Semantics

A function that takes a function as a parameter or returns a function value has order n+1, where n is the order of its highest-order parameter or returned value T F

T

C++, permit the programmer to overload function names True False

T

In C++, the namespace specifies the visibility of its components T F

T

ML's syntax keeps types and expressions separated T F

T

A function's type specifies the function's domain and range t/f

True

A function's type specifies the function's domain and range. T/F

True

A token in a grammar cannot be broken into smaller pieces T/F

True

A tuple type is a set of Cartesian product t/f

True

A type is a set T/F

True

Andalso has higher precedence than orelse T/F

True

Any term can appear in a query, including variables T/F

True

Any term can appear in a query, including variables. T/F

True

C++ allows virtually all operators to be overloaded. T/F

True

Each rule in a match is a block. T/F

True

Given the following grammar: <S> ::= <NP> <V> <NP> <NP> ::= <A> <N> <V> ::= loves | chases | hates | eats <N> ::= dog | cat | rat <A> ::= a | the "The cat hates the dog" is a sentence (i.e. <S>) T/F

True

In C, pass by reference equivalent pass the address by vale. T/F

True

In most programming languages, such as ML, Java, and Prolog, the correspondence between actual parameters and formal ones is determined by their positions in the parameter list. T/F

True

ML pattern introduces new variables T/F

True

Parent(adam, Child) and parent(adam, seth) unify by binding the variable Child to the atom seth. T/F

True

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

True

The activation record for the following function can be deallocated as soon as the function returns. Fun f x = map ~ x; T/F

True

The following function will work on any list with two elements: Fun f [a, _] = a; T/F

True

The natural implementation of Macro Expansion is to use textual substitution before compiling T/F

True

The simplest thing in Prolog database is fact: A term followed by period. T/F

True

To avoid problem of capture, we use variable renaming. Every time a clause is used, it will be given a fresh set of variable names, different from all the other names that have been used. T/F

True

When parameters are passed by value, changes to a formal parameter do not affect the actual parameter. T/F

True

When two expression have the same lvalue, they are aliases of each other T/F

True

parent(adam,Child) and parent(adam,seth) unify by binding the variable Child to the atom seth T/F

True

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); } a. 7 b. Unknown c. 3 d. 4

a

Given the following function: fun f(a : char, b : char) = (a <> b); which of the following result true? a. f(#"A", #"a"); b. f("A", "a"); c. f("A", "A"); d. f(#"A", #"A");

a

In ML, you can add a parameter of any type to a data constructor, using the keyword ______ a. of b. struct c. typedef d. def

a

In java, which of the following operator has the highest precedence? a. negation b. * c. subtraction d. addition

a

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 a. depth, left-to-right b. breadth, left-to-right c. depth, right-to-left d. breadth, right-to-left

a

Regarding to the spectrum of language-system solution, which of the following results a standard compiled language system? The intermediate language to be the physical-machine language The intermediate language to be the same as the high-level language. The intermediate language to be a lower-level langauge, like the bytecode of the JVM The intermediate language to be a tokenized form

a

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; a. Yes b. No c. Cannot determine d. The function has an error

a

The question: whether a given occurrence of a name is in the scope of a given definition? If the questios is answered at compile time, it is called __________ scoping a. static b. dynamic c. systematic d. traditional

a

Which of the following is left-associative? a. <exp> ::= <exp> + <mulexp> | <mulexp> <mulexp> ::= <mulexp> * <rootexp> | <rootexp> <rootexp> ::= (<exp>) | a | b | c b. <exp> ::= <mulexp> + <exp> | <mulexp> <mulexp> ::= <rootexp> * <mulexp> | <rootexp> <rootexp> ::= (<exp>) | a | b | c

a

what is the output of following map (op +) [(1,2),(3,4),(5,6)]; a. val it = [3,7,11] : int list b. val it = [9, 12] : int list c. error d. val it = [3,7,11] : int * int * int

a

Consider the simple rule: p :- q, r. To prove a goal via this rule, which of the following must be success? a. prove q b. unify the goal with p c. prove r d. unify goal with q and r

a b c

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

a b d

Which two address are important when a function returns? a. the address of the activation records that function was using b. the address of main function c. the address of the called function d. the address of the machine code to return to in the calling function

a d

A type with type variables is a _________ a. unitype b. polytype c. multitype d. monotype

b

Consider the following function fun merge (nil, ys) = ys | merge (xs, nil) = xs | merge (x :: xs, y :: ys) = if (x < y) then x :: merge (xs, y :: ys) else y :: merge(x :: xs, ys); What is the result for the following statement: merge ([1, 2, 3], [4, 5, 6]); a. val it = [1, 4, 2, 5, 3, 6 ] : int list b. val it = [1, 2, 3, 4, 5, 6] : int list c. val it = [1, 2, 3, 4, 5, 6] : list d. val it = [1, 3, 5, 2, 4, 6] : int list

b

Consider the following grammar, <exp> ::= <exp> + <mulexp> | <mulexp> <mulexp> ::= <mulexp> * <rootexp> | <rootexp> <rootexp> ::= let val <variable> = <exp> in <exp> end | (<exp>) | <variable> | <constant> which of the following is true? a. The grammar is umbiguous b. The operators are left associative c. + has higher precedence d. There is an error in the grammar

b

Each time the user runs the program, the system ____________ is responsible for getting the program into memory a. compiler b. loader c. editor d. linker

b

Given datatype day = Mon | Tue | Wed | Thu | Fri | Sat | Sun; and fun isWeekDay Sat = false | isWeekDay Sun = false | isWeekDay _ = true; What is the value of isWeekDay Mon; a. false b. true c. Error

b

Given fun g a = fn b => fn c => a+b+c; What is the type of g? (int -> int) -> (int -> int) int -> int -> int -> int int * int * int -> int int * int -> int -> int

b

Suppose in ML datatype day = M | Tu | W | Th | F | Sa | Su; fun isWeekend x = (x = Sa orelse x = Su); What is the result of statement: isWeekend M; a. val it = true : bool b. val it = false : bool c. There is a syntax error

b

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

b

The term late binding is another way of saying ______________ binding a. coding time b. running time c. compiling time

b

What is the output of the following in ML? 1 < 2 or 3 > 4; a. val it = true : boolean b. Error c. val it = true : bool d. val it = false : bool

b

What is the output of the following in ML? 1.0 < 1.0; a. val it = false : boolean b. val it = false : bool c. val it = true : boolean d. val it = true : bool

b

What is the output? foldr (op +) 0 [1,2,3,4]; a. error b. val it = 10 : int c. val it = [1,2,3,4] : int list

b

What is the result of the following? [1, 2, 3] @ [3, 4, 5]; a. val it = [1, 2, 3, 4, 5 ] : int list b. val it = [1, 2, 3, 3, 4, 5 ] : int list c. Error d. val it = [1, 2, 4, 5 ] : int list

b

What is the type of the following result? [[1, 2, 3], [1, 2]]; a. (int * int) list b. int list list c. list list d. int list

b

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

b

Which of the following ends a conjunctive query? a. semicolons b. periods c. commas d. questions marks

b

Which of the following is not a ML pattern? a. A cons of patterns b. .... c. A constant d. _

b

Which of the following is not a unary operator? a. -- b. + (addition) c. - (negation) d. ++

b

Which of the following pattern in ML matches anything? a. ... b. _ c. ~ d. ()

b

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 next recursive call yet)? a. 1 b. 2 c. 3 d. 4

b c d

Which of the following are types of ML? a. double b. bool c. char d. int

bcd

Based on code line datatype 'a option = NONE | SOME of 'a; val x = SOME 4; Which of the following is true? a. val x = SOME 4 : int b. val x = 4 : int option c. val x = SOME 4 : int option d. val x = SOME 4 : option

c

Consider the following code lines: datatype 'element mylist = NIL | CONS of 'element * 'element mylist; CONS(1, CONS(2, NIL)); Which of the following is true? a. val it = (1, 2) : int mylist b. val it = CONS (1,CONS (2,NIL)) : mylist c. val it = CONS (1,CONS (2,NIL)) : int mylist d. val it = [1, 2]: int list

c

Consider the following halve function: fun halve nil = (nil, nil) | halve [a] = ([a], nil) | halve (a :: b :: cs) = let val (x, y) = halve cs in (a :: x, b :: y) end; What is the result of the following statement? halve [1]; A. val it = ([], [1]) : int list * int list b. val it = ([], [1]) : int list * int c. val it = ([1], []) : int list * int list d. val it = ([1], []) : int * int list

c

How many blocks it contains? case x of (a,0) => a | (_,b) => b 4 1 2 3

c

In C++, which f gets called for f('a', 'b') ? a. void f(int x, char y) { ... } b. void f(char x, int y) { ... } c. Compile error due to ambiguous

c

What is the output? ~ 3 + 5; a. val it = ~2 : int b. val it = ~8 : int c. val it = 2 : int d. val it = 8 : int

c

What is the result of the following? (if 1 < 2 then 34 else 56) + 1; a. Error b. val it = 57 : int c. val it = 35 : int

c

Which of the following is a correct EBNF notation for statement-list? a. < statement; > b. ( statement;) c. { statement;} d. [ statement;]

c

Which of the following operator has second highest precedence? a. > b. ~ c. * d. andalso

c

Which of the following produce error message in ML? 1 * 2; 1.0 * 2.0; 1 * 2.0; None of the above

c

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. a b. b c. 1 d. 2

c d

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

c d

Any type that a program can define for itself (using the primitive types) is a _______________ type

constructed

Consider the following code line datatype 'data tree = Empty | Node of 'data tree * 'data * 'data tree; val treeEmpty = Empty; val tree2 = Node(Empty,2,Empty); val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)); Which of the following is NOT true? a. val treeEmpty = Empty : 'a tree b. val tree2 = Node (Empty,2,Empty) : int tree c. val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)) : int tree d. val tree123 = Node(1, 2, 3): int tree

d

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

d

Consider the following formal semantic: E subscript 1 rightwards arrow v subscript 1 comma space E subscript 2 rightwards arrow v subscript 2 minus minus minus minus minus minus minus minus minus p l u s left parenthesis E subscript 1 comma E subscript 2 right parenthesis rightwards arrow v subscript 1 plus v subscript 2 Which of the following is a Prolog Implementation of this semantic? a. val1(plus(X,Y),Value) :- value = X + Y b. val1(pluss(X,Y),Value) :- Value is X * Y. c. val1(plus(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), d. val1(pluss(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue + YValue.

d

Given the following grammar: <S> ::= <NP> <V> <NP> <NP> := <A> <N> <V> := loves | chases | hates | eats <N> := dog | cat | rat <A> := a | the Which of the following are the nodes in the parse tree of "the cat eats the rat" that only have a leaf as child. a. <S> b. <NP><V><NP> c. the cat eats the rat d. <A><N><V><A><N>

d

What is the binding time for the following in C or C++? The location in memory of a local variable in a function? Language implementation time load time Language definition time Runtime

d

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

d

What is the result of the following: let val x = 1 val y = 3 in x + y end; a. val it = 3 : int b. val it = 1 : int c. val it = 2 : int d. val it = 4 : int

d

Which of the following defines the <match> in ML? ::= <rule> '|' <match> ::= <rule> '|' <rule> ::= <rule> ::= <rule> | <rule> '|' <match>

d

Which of the following have the same effect as: fun f x = x * x; val f => fn x = x* x; val f = x => x * x; val fn x => x* x; val f = fn x => x * x;

d

Dynamic type checking determines a type for everything before running a program. T/F

false

What is the result of the following? ?- not(member (1, [1, 2, 3])). true. error false.

false

The ________________ of a programming language defines what the program's behavior and meaning is.

semantics


Ensembles d'études connexes

Binatang di Rumah (Animals at the House) - with the colour descriptions

View Set

Python- OOPS python interview questions

View Set