Final Exam 3302

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following can you NOT do with pattern matching?

- (ans) Check equality of first two list elements. -Measure a list's length. -Match hd::rest or rest::tl to select its head or tail. -Checks form of actual parameters.

Which of the following is NOT a "term"?

- (ans) True and false. -The arithmetic expression, a + b - c. -Strings, binary trees and lists. -The functions f(a, b), g(a, X) and h(f(a, b), Y).

Which of the following are in the language of first-order logic?

- An alphabet. - Terms defined over the alphabet. - Well-formed formula defined over the alphabet

When the subclass' type T becomes a subtype of the all-inclusive superclass' type S, the user interface of T also becomes a subset of its inherited S. (T/F)

False

Java's inheritance hierarchy is a tree, and its inheritance relation is a sub-hierarchy of its inheritance hierarchy. __(T/F)

False, True (missing subtupe hierarchy)

Higher-order functions

Functions returning other functions or passing functions as other functions' parameters, which are central to this mode of computation.

Java's design language

Generic pseudo-language for describing O-O's flexible and extensible data abstraction and its polymorphism, generality and subtype concepts.

Q32 - Martelli and Montanari's algorithm

Given a set of equations E = {s1 = t1, ...,sn = tn}, it either fails or it produces the solved form: {X1=r1,...,Xm=rm}, in which the X1,...,Xm, are distinct variables that do not appear in the terms r1,...,rm. If indeed it exists, the equation E's MGU is then the set of bindings θ = {X1/r1,...,Xm/rm}.

Order the steps of JVM's dynamic special method dispatch:

- Deliver a this pointer to the method. - Referring to the object o in o.m(parameter), get the name of m from the constant pool. - Look for the methods m in all other objects. Change the o.m(parameter) instruction into the invokevirtual nameIndex instruction. - Change the invokevirtual nameIndex instruction into the invokevirtual_quick offset numParms instruction. - Execute the invokevirtual_quick offset numParms instruction.

Which of the following accurately describe inheritance & subtypes in C++?

- Derived C++ classes (subclasses) introduce the inheritance relation. - And they introduce the subtype relation, when derived classes declare their base classes (superclasses) public. - If not public, the subtype relation disappears. - Instead of Java's interface subtypes, C++ offers pure virtual abstract base classes without implementations. - These are subtypes without inheritance.

Which of the following essential concepts of modern imperative languages were first developed in functional languages?

- Generics. - Polymorphism. - Type safety. - Interactive environment. - Rich system of types. - Pattern matching. - Variables. - Assignments.

Q31 - Which of the following statements is true regarding Prolog's deductions?

- Prolog handles an algorithm's control mechanism, which imperative programmers must handle themselves. - Its computational mechanism is the resolution deduction rule. - The abstract machine exhaustively searches the solution space for facts and rules that can be combined to deduce (by a unification process) a programmer's stated conclusion. - Like impure LISP, Prolog grudgingly accepts users' suggestions on how to direct this search.

Instantiations

Instances of a class that actually occupy memory and execute at runtime.

Java & ObjectiveC

Leading O-O languages in the niche Web and mobile programming markets.

Mark & compact

Memory fragmentation is reduced by moving all live objects linearly into contiguous blocks of similarly aged objects

Dangling references

Memory made inaccessible by the corruption of its pointer.

Correct

Neither the ADT client nor the ADT's implementer violates the ADT's signature or its operation's specifications.

Methodologies(evolution factors)

Object-orientation is boosting software development productivity and quality.

Theory(evolution factors)

Occasionally we academics help out by showing that goto must go, for example.

Wildcard

One "unknown" (the '?' character) substituted for a type in a subclass definition enables the compiler to adapt the subclass to any type context.

Q28 - Reduction

Recursive evaluation of expressions, a layer at a time.

Lambda Calculus

Simple and powerful formal system at the center of all functional languages

Derived class

Synonym in C++ for "subclass" in Java.

Abstraction

A mechanism for passing from one expression denoting a value to one denoting a function.

Inherit

To acquire a parent's traits, which can be adapted to variety of uses.

SECD machine

A prototype abstract machine for higher-order functional languages, which uses the evaluation-by-value strategy.

Type system

A set of constructs and mechanisms that define and regulate its use of types.

CLP

A small Prolog extension that propagates constraints from input-to-output or output-to-input.

Representation independence

Users may rely upon abstract specifications.

Dereference

Using the memory address stored in a pointer to access an object.

Counter c = new Counter()

Create an instance of the Counter class in the heap.

Signature

Declarations of all ADT operations' names, parameter types and returned types, which the ADT offers to its clients.

solve()

A MATLAB function that returns the values of n variables given in n simultaneous equations.

Q35 - Hardware(evolution factors)

Cheaper, smaller and cooler all urge the development of higher productivity programming languages.

Dependability what means to measure its values?

Ethics.

Correctness what means to measure its values?

Total cost.

A first-order logic alphabet includes a pair of symbols (Σ,Π) designating a function and its predicate(s), which are interpreted as relation(s). (T/F)

True

Pure functional languages can be proved to be correct. (T/F)

True

Modules

- Cohesive clusters of interrelated types (data structures). - All of their implementations are hidden. - Some of their operations may be hidden. Inside them are many ADTs, each with its own data structures and operations. (Those ADTs' visibilities may vary; some may be polymorphic; and they may be separately compiled.) - Some of their private parts may be imported. - For maximum utility, they should be made polymorphic whenever possible.

Which of the following accurately describes method dispatch in C++? __

- Dynamic dispatch in C++ is accomplished by subclasses overriding virtual methods. - To save runtime, static dispatch also overloads a superclass' non-virtual method in a subclass. - Compile-time type matching of those methods' return values and parameters in the context of each invocation resolves the correct method.

Order the steps of JVM's dynamic interface method dispatch:

- Execute the invokeinterface_quick method_name offset instruction. -Loop through all implementation instances of the interface, searching for the method's name index, with invokeinterface nameIndex in the body of the loop. - Rewrite the invokeinterface nameIndex instruction as the invokeinterface_quick method_name offset instruction. - Look in the vtable to verify the name, index and offset. - If not, correct the offset. - Invoke the method.

Which of the following accurately describe Prolog's clauses?

- In the general sense of first-order logic, a clause is this formula: A1,...,Am ← B1,...,Bk - A definite program clause has only one un-negated atom (m = 1). - A Prolog "fact" is a definite clause containing no negated atoms (k =0). - Prolog's query or goal is a "negative clause" in which m=0.

Which of the following accurately describe(s) Prolog variables?

- It is an unknown that can assume a value of any predetermined set of definite terms in the first-order logic alphabet. - It can be bound to a term only once. - Its value can be partially defined, to be defined later, because the term to which it is bound may change. - A process of successive approximations may continually change it toward a specified goal. - Its bindings are bidirectional. - Bidirectional bindings enable a logic program's use in very different ways.

How does replicated multiple inheritance handle code like that shown below? __ Top bottom.f(); Top bottom.z = 1;

- It reorganizes the diamond inheritance pattern into a linear linked list. - It raises a runtime exception. - It adds yet another vtable.

Constructor description:

- It runs automatically, when a derived class is created. - The base class may do the same, when the derived class is created. It typically does a once-and-for-all initializations. - It has the same name as its class. - The compiler can choose among multiple constructors in a class, by matching their return types and argument types with static context. - It also frees any memory that the class may have allocated in the stack or heap. (Not accurate)

Which of the following Java methods can the JVM dynamically dispatch? __

- Static methods, which are associated with classes, not instances of classes. - Abstract (virtual) methods, which pass references to the objects on which the methods are called. - Special methods, whose invocations pass this pointers to the methods' starting addresses. - Interface methods, which are superclass' completely abstract classes, entirely without implementations.

What is part of every ADT?

- The new type's name. - The new type's implementation. - Names of the new type's operations and the concrete types of their parameters and returned values. - Those operations' implementations. - A security capsule, which separates all operations' user interfaces from their implementations.

What are a "formula"?

- True and false. - > (X,Y) ∧ > (Y,Z) → > (X, Z). - > (3, 2).

Which of the following accurately describes protected visibility flag?

- Unlike public and private, protected visibility makes subclasses look the same as their superclasses to a client. - Without "protected," superclasses' private code would be invisible to both clients and subclasses. - Unfortunately, code maintenance in a "protected" superclass does not automatically propagate to subclasses and must be repeated there. - In C++, "protected" affects only class visibility. - In Java, "protected" applies to entire packages.

Q30 - Which of the following accurately describes most functional languages' abstract machine?

- We call it an "SECD" machine. - S is a stack of partial results of ongoing computations. - E (environment) is a list of value-name associations. - C (control) is a stack of expressions to be evaluated. - D (dump) is a stack of saved prior machine states.

Turing machine vs. lambda calculus

- both: Turing completeness, Express(es) all computable algorithms, Compilers and interpreters can abstract the minimal instruction set to any arbitrarily high level. - TM: Minimal instruction set: INC, DEC and JN, Basic constants: (-128, ..., 127), Supports imperative languages' assignments of states. - LC: Minimal instruction set: AND, OR and NOT, Basic constants: TRUE and FALSE, Supports functional languages' reduction of expressions

Which of the following properly describe(s) the Java programming language?

-A program written just once can run anywhere. -It was perfectly timed to solve a problem that Web servers were having with thin clients. -Clients' Java Virtual Machine (JVM) runs on top of any architecture. -Java programs are type safe at compile time, their intermediate-language bytecode is static-type checked; and the JVM interpreter does runtime type checking. -Web browsers don't mind Java being slow.

Q36 - Which of the following properly describe(s) the C++ programming language?

-A proper superset of C. -The C++ compiler was to accept standard C code, and its compiled C code was to run as well as C always had. -Garbage collection was ruled out for C++, because it would have degraded C's performance. -Each C++ object appeared to be a C struct. -The very efficient C++ method lookup mechanism uses C's legacy static type system.

describe(s) the Ada programming language

-Charles Babbage's female programmer. -The result of a U.S. -Defense development contract. -Based on Pascal. -It took 3 years to write the compiler. -The only acceptable language for U.S. weapons development, until C++ replaced it in 2002. -Innovated linguistic constructs and implementation mechanisms for concurrent tasks' synchronization and communications.

Which of the following properly describe(s) the CLP language?

-Constraint Logic Programming languages manipulate relations over appropriate domains. -It added to logic programming a classical mechanism for solving constraint problems. -It was an early extension of Prolog, which allowed linear equations and inequalities over terms (rational trees). -Its later enhancement became a proper subset of logic programming and a superset of all existing logic languages. -An even later enhancement allows a variety of constraints on finite domains.

Reference counting

-Garbage collector recognizes objects not pointed at by their zeros. -Reference counting objects that point at each other cannot be detected or collected as garbage.(T)

Q33 - Accurately describe the Datalog language

-It is a simplified logic language for relational databases. -Unlike SQL, it is entirely devoid of function symbols. -Extensional, intentional and comparison predicates are distinguished. -Extensional predicates (facts) cannot occur in the head of clauses with a non-empty body. -If a variable appears in the head, it also must appear in the body of a clause. -A comparison predicate can occur only in the body of a clause. And the variables in such a predicate also must occur in another atom in the body of the same clause. -Its recursion is an advantage over data manipulation languages.

Q27 -What advantages accrue from Java's generics, compared with C++ templates?

-Java carefully type checks the generic method and then actually replaces the generics with the context's required types and then actually replaces the generic with the context's required types at compile time. - Java's JVM runtime environment needs no modifications, like those performed by the C++ linker for templates. - Java's generic and non-generic code can be safely mixed, under the compiler's strict supervision. - Dynamic casts that the compiler inserts during erasure ensure runtime type error detection. - C++ templates are resolved outside their methods by a dumb linker.

Locks & keys

-Mismatched marks on dereferenced pointers and their allocated memories prompts abstract machine to raise exception. -Every pointer is marked to match its memory area allocated in the heap. -Every time the pointer is dereferenced, the abstract machine checks for a match. If not, it raises a runtime error. -When memory is deallocated, the abstract machine changes its markings to ensure that it matches no pointers. -This costs twice the space of the alternative, but the matching markers are easily deallocated. -This allocation and deallocation also make them more speed costly than the alternative.

Pure functional programming paradigm

A computation model that solves problems by rewriting expressions, without modifying variables.

SLD Resolution

A deduction rule that computes the "answers" of logic programming.

Application

Abstraction's dual, by which a function is applied to an argument.

Q34 - Logic programming syntax

An alphabet, (variable) terms and well-formed formulas.

Counter.set(x) = 1

Change the value of the Counter class' private count.

What does the following code statement do? (fn x => exp1) exp

It binds the variable x to the expression exp within the limited scope exp1.

Overloaded

It denotes more than one object, or when context determines which object is denoted by that name.

most general unifier

It finds specific substitutions for terms in clauses, in a process that resembles solving mathematical equations.

Constructor

It initializes a class automatically, when an instance is created.

Implementation(evolution factors)

Language constructs must evolve gracefully to assure customers' adoption of new versions.

Q23 - Simula & smalltalk

Object-oriented language pioneers.

z = Counter.x

Obtain a public count's current value.

y = Counter.get(x)

Obtain the private count's current value.

Applications(evolution factors)

Our needs change from winning WWII ...to counting our money to ...enhancing our daily experiences.

Predicate calculus

PROLOG's first-order logic symbols express all properties of elements of a fixed domain of discourse, D.

Atanasoff and Berry

Patented the first electronic digital computer, for use in calculating hybrid seed corn statistics.

Vtable

Pointers to all methods (along with their parameter and returned value types) gathered for each class definition before runtime. (A.K.A. constant pool.)

Q22 - Abstract data type

Provides values and operations that echo customers' low-level requirements.

Interface

The visible parts of an ADT, which include its signature and its operation's specifications.

Prolog examples

They build students' fluency, while suggesting database and constraint management applications.

Prolog's extensions

They make the language easier to use, while compromising its proof of correctness.

Can ADTs be made to perform almost as well as OOClasses?

Yes, by duplicating an existing ADT and overloading its argument types for increased functionality. (This is hard to compile and maintain.)

Pointer reversal

While traversing downward (and upward), the garbage collector reverses pointers behind it, instead of storing its reverse path on stack.

Essential feature of O-O paradigm

- Encapsulation - Abstraction - Subtypes - Inheritance - Dynamic method selection - Effective interactions of the above

Mark & sweep garbage collector

-Reclaims abandoned memory in languages that lack explicit memory deallocation. -After marking all heap objects "not in use," this garbage collector traverses the root set of active stack pointers recursively depth-first, marking only those objects "in use." Then the former are returned to the free list. -It runs only when too little memory is available. -Due to its external fragmentation, large blocks of memory are hard to allocate. -Much runtime is wasted searching the entire heap. -Different ages of objects close together degrades locality of reference; i.e., cache, instruction prefetch, branch prediction and pipelining don't optimize performance. -Garbage collection uses reference counters

Q21 - Type inference process steps

1. Copy all explicit types from the compiler's symbol table and source code to nodes in the tree. 2.Use equality constraints to determine types of all expressions. 3.Use the unification algorithm to resolve ambiguities.

Subclass

A class that inherits the software designer's prototype and adds an instance variable or a method of its own.

Covariant

A function that respects the preorder.

Contravariant

A function that reverses preorder; i.e., x ≤ y implies f(x) ≥ f(y).

Evaluation-by-name

A redex is evaluated before its argument part.

normal order evaluation

A redex is evaluated before its argument part.

outermost evaluation

A redex is evaluated before its argument part.

Q24 - Class

A static type declaration of a record-like structure of instance variables and methods that operate on them.

Cohesive

All parts work together toward a common purpose.

this.x = 0;

Clear the count from inside the Counter class

Locality of reference

Cache, instruction prefetch, branch prediction or pipelining can't optimize abstract machine's performance.

Cheney's algorithm

Entirely without fragmentation, it copies recursively visited nodes into one long to-space queue.

innermost evaluation

Evaluate a reducible expression (redex) only if the expression, which constitutes its argument part, is already a value.

Copy collector

It recursively copies only live objects from the heap's from-space into its equally sized, compacted to-space, modifying all pointers on the fly.

Superclass

Java's name for a software designer's prototype class that programmers use with minimal editing.

Maintainability what means to measure its values?

Software maintenance efforts

Readability what means to measure its values?

Software maintenance efforts

Efficiency what means to measure its values?

Speed and space

Subtype relation

T is a subtype of S, when the interface of S is a subset of the interface of T.

Ada

The DoD's only acceptable mission-critical programming language (until recently).

C++

The U.S. Department of Defense' (DoD's) only acceptable mission-critical programming language currently.

Implementation

The hidden code that constructs, transforms and observes to create an ADT, in terms of predefined types and component ADTs.

Accessing a method via the vtable costs only two indirect accesses at runtime. __ (T/F)

True

All of module's implementations and operations are hidden?(T/F)

True

Each subclass gets a copy of its superclass' vtable with shadowed data and overridden methods appropriately modified. __ (T/F)

True

Java extends single inheritance for classes but implements multiple inheritance for interfaces. __(T/F)

True

Q26 - Can replicated and shared multiple inheritance be combined?

Yes, but doing so is too complicated to explain here.

Evaluation-by-value

- Saves every value and reuses it, instead of repeating costly evaluations. - LISP, Scheme and ML use it, because it is much more efficient.

Description of delegation

- A new object clones a "prototype" parent object. - If it lacks a method, it delegates its client's calls to its parent's method instead. - The delegation mechanism makes modern inheritance flexible and powerful. - Objects can dynamically change behaviors by changing parents at runtime.

What does ADTs offer?

- Encapsulation and information hiding. - Inheritance of particular operations in existing similar constructs. - Type compatibility with those operations. - Dynamic (runtime) selection of operations, based on the clients' preferred types.

lazy evaluation

- Saves every value and reuses it, instead of repeating costly evaluations. - Miranda and Haskell use it, because it seldom diverges.

Client

A programmer who applies an ADT, but does not create it.

Characterize a copy collector

-It runs when a memory allocation gets delayed for lack of from-space memory. -It recursively copies only live objects from the heap's from-space into its equally sized, compacted to-space. -It modifies all pointers on the fly. -The from- and to-spaces then swap and repeat. -Entirely without fragmentation, Cheney's algorithm copies recursively visited nodes into one long to-space queue. -Precautions are taken to prevent copying an object of multiple pointers many times. -Runtime is proportional to the number of live objects, because dead ones don't move. -Increasing memory size decreases runtime by reducing garbage collector calling frequency.

What prevents a client from violating a programmer's abstract data type.

-They must be accessed transparently. -ADTs are opaque. -Clients can't change what they can't see

Describe the represenation independence property

-Two correct implementations of a single ADT specification. -They cannot be distinguished by the ADT's clients. -Replacing the ADT's correct implementation with some other correct implementation causes no new errors in client software. -That correctness is relative to the ADT's signature in a type-safe language.

Base class

Synonym in C++ for "superclass" in Java.

Interface(2)

The public part of a class that tells clients how to use it.

Diamond Problem

of a subclass double-inheriting from superclasses, both of which unknowingly inherit from a single supersuperclass, actually arises frequently

Which of the following accurately describes method dispatch in the Common LISP Object System (CLOS)? __

- In CLOS, all methods are globals. - Each "multi-method" name is overloaded with many types and implementations. - A multi-method implementation is selected at runtime, based on the receiving object's and the arguments' types. - CLOS is slow.

In what ways has the object-oriented paradigm proved useful?

- It creates abstractions in flexible and extensible ways. - It (and delegation) encapsulate data. - It controls compatibility relations between types (i.e., subtyping). - It reuses code via single and double inheritance. - It dynamically dispatches methods. - It supports subtype polymorphism. - Java's step-child covariant arrays offer limited polymorphism. - It enables overriding covariant and contravariant methods. - Its techniques have improved software development life cycles for other than O-O languages by providing semiformal rules for organizing conceptual objects and operations.

Which of the following accurately describe the JVM's dynamic method dispatch? __

- JVM is the abstract machine that interprets the Java compiler's intermediate byte-code language. - It places invoked methods and their parameters on the stack, without hardware-dependent registers. - In the compiled class' file, a constant pool describes its instance variables, methods, their types, resolved (indices of) names, names of other classes it uses, etc. - Offsets are found at runtime, not compile time.

Which of the following accurately describes Java arrays?

- Java arrays do preserve subtypes. - Covariant arrays do provide a limited form of polymorphism. - The Java compiler attaches dynamic casts to arrays that evoke runtime errors, if coders fail to respect their type contexts. - Arrays were an early language design error that should have been corrected with the addition of generics, but wasn't.

Does the C++ code sequence below require a dynamic downcast? __ A Ide (A x) {return x;} C cc = Ide(c);

- No, the value returned at runtime always will be the parameter's type. - Yes, efficient static checking calls for stricter type limitations than are semantically reasonable.

Which solves the "diamond problem"?

- Raise an exception. - Require the A::f() or B::f() notation in calls. - Follow a convention of, for example, choosing the first class named in the subclass' extension clause. - Override the superclass' definition of f() in subclasses.

Accurately describe Smalltalk's subtypes?

- Smalltalk programmers believe it is a typeless O-O language. - Defining a Smalltalk subclass does not generate a subtype, because Smalltalk allows subclasses to remove methods from their superclasses. - Only its designers know that Smalltalk does have subtypes, because it allows programmers to freely use an object of class T in place of an object of class S (without generating additional errors).

Tombstones

- They force double-indirect referencing of allocated memory, and they continue pointing at "dead" memory when it is deallocated. -In allocating heap or stack memory, the abstract machine saves memory addresses there, forcing the programmer's pointer to access the memory double-indirectly through them. -When the pointer is dereferenced, or when one pointer is assigned to another, only the pointer's contents are modified. -When heap memory is explicitly deallocated, or when an activation record pops off the stack, they get marked "RIP" to indicate that their memory buffers are dead. -Allocating them in protected memory (where hardware can interrupt the abstract machine) consumes costly space. A small garbage collector may trade speed for space by recycling them. Double-indirection access to a great many small data items inflicts a high runtime cost.

Q29-Which of the following accurately describe(s) functional languages?

- They manipulate high-order functions and variables alike. - They pass either of those as parameters or as other functions' returned values. - Interpreting them evaluates an expression by recursively reducing its complexity, until the result is an irreducible value. - This "computing" consists of rewriting the expression by substituting definitions of simpler expressions and values for their every occurrence. - These rewriting steps can proceed from innermost arguments outward (by-value) or from outermost function inward (by-name). - Those regarded as "pure" are sufficient to express programs for every computable function (i.e., Turing complete), but they could be easier to use and more powerful. -Their compilers generate efficient object code for heavily used expressions stored in the environment.

Polymorphism

- fun f(n) {return n+1;} - Universal polymorphism : It may be parametric or the more limited subtype.

If the by-value or lazy strategy succeeds in reducing a closed expression to a primitive typed value, then by-name also can. If by-name fails to reduce a closed expression (i.e., it diverges), the others will fail too. (T/F)

True

Java's compiler assumes that two wildcards in the same construct are completely distinct variables. (T/F)

True

Java's generic type definition DefPara<T> does not preserve the subtype hierarchy. (T/F)

True

Q25 - If a subclass' shadow variable does not match the type of its instance variable, it binds to the next superclass' variable that (T/F)

True

True or False: For the compatible subtype relation, every instance a of class A has all of the superclasses of A as its type. __

True


Kaugnay na mga set ng pag-aaral

1.EL LENGUAJE EN LA RELACION DEL HOMBRE CON EL MUNDO

View Set

Ch 70 Oncologic or Degenerative Neurologic Disorders

View Set

GEOG 103 EXAM 3 WKU ch. 13, 14, & 16

View Set

Palindrome Practice Questions - Java

View Set

Chapter 7 - Customer Value-Driven Marketing Strategy: Creating Value for Target Customers

View Set