












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Polymorphism. (Definition. Examples) - Answer: Allows a single body of code to work with objects of multiple types. It may or may not need run-time type checking. For example, integers and floats are implicitly polymorphic since you can add, subtract, multiply and so on, irrespective of the fact that the types are different. They're rarely considered as objects in the usual term. Discrete types and scalar types (Examples) - Answer: Discrete Data Type - represents items that can be counted. They can be classified as integers, Booleans, characters, enumerations, or subranges. Must have a clear successor and predecessor.
Scalar Type - It is a simple single numeric value (i.e. 1, 2/3, 3.14, etc.) usually an integer, fixed point, or float, as opposed to an array, structure, object, or complex vector which contain more than one single numeric value. Alignment of struct/record data types. - Answer: • ORTHOGONALITY is a useful goal in the design of a language, particularly its type system. It means that features can be used in any given combination, the combinations all make sense, and the meaning of a given feature is consistent, regardless of the other features with which it is combined.
In the first statement, the right hand side of the statement refers to the value of a, which we wish to place into d. In the second statement, the left hand side refers to the location of a, where we want to put the sum of b and c. •Variables as values vs. variables as references -value-oriented languages •C, Pascal, Ada -reference-oriented languages •most functional languages (Lisp, Scheme, ML) •Clu, Smalltalk -Algol-68 kinda halfway in-between -Java deliberately in-between •built-in types are values •user-defined types are objects - references Name equivalence and structure equivalence. - Answer: Name Equivalence - based on declarations. Two types are the same is they have the same name. Each type declared introduces a new type distinct from all others. Used in Java and Ada. Structural Equivalence - Based on some notion of meaning behind those declarations. Two types are equivalent if they have the same structure. Used in Algol-68, Modula-3, and ML. Depends on simple comparison of type descriptions substitute out all names
Type conversion and coercion. - Answer: Type Conversion (Explicit) - Converting one type of data to another type. It is also known as type casting. It can be used to pass a value to a function where the parameter is of a different data type or to return a value from a function where the function return type is of a different data type. Implicit - performed whenever one fundamental data type is expected but a different fundamental data type is supplied and the user does not explicitly tell the compiler how to perform this conversion.
Type Coercion (Implicit) - it is the conversion of one type of object to a new object of a different type with similar content. A common example is the coercion of string "5" into an integer 5 or a double 5.0. Coerces an expression to be of the proper type
Associative Array. (Definitions. Implementations. Challenges. Associative arrays in languages). - Answer: An abstract data type composed of a collection of (key, value) pairs, such that each possible key appears with this data type. It is a non discrete index type. Must be implemented with hash tables or search trees. They resemble the dictionary or map types supported by the standard libraries of many object oriented languages. In C++, they are typically defined by overloading operator[]. C#, like C++, provides extensive facilities for operator overloading but it does not use these facilities to support associative arrays. Instead, the language provides a special indexer mechanism, with its own unique syntax. Most script languages, such as Python, PHP, Javascript support associative array.
They are arrays that can use non-integer type values as indices:
calling sequence and subroutine prologue and epilogue. space is saved by putting as much in the prologue and epilog as possible. Tasks that must be accomplished on the way into a subroutine include passing parameters, saving the return address, changing that stack pointer to allocate space, saving registers that contain important values and that may be overwritten by the callee, changing the frame pointer to refer to the new frame, and executing initialization code for any objects on the new frame that require it. Time may be saved by putting stuff in the caller instead, where more information may be known.
proc(&a,b); -or directly passed by reference (C++) void proc(int& x, int y) {x = x + y } proc(a,b); Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value. public void badSwap(int var1, int var2){ int temp = var1; var1 = var2; var2 = temp; } When badSwap() returns, the variables passed as arguments will still hold their original values. The method will also fail if we change the arguments type from int to Object, since Java passes object references by value as well. What is the accessibility rules for C++ inheritance classes for example, class circle:protect shape { ....... } - Answer: C++ allows members of a class to be designated as Public, Private, or Protected. Public members are visible anywhere the class declaration is in scope. Private members are only visible inside the class's method. Protected members are visible inside methods of the class or its descendants.
Visibility rules
c. fib(0, 0). fib(1, 1). fib(X, Y) :- X > 1, X2 is X - 2, fib(X2, Y2), X1 is X - 1, fib(X1, Y1), Y is Y1 + Y2. Understand vtable and dynamic method binding. - Answer: - They are implemented by creating a dispatch table (vtable) for the class and putting a pointer to that table in the data of the object
c. 2*2 = 4 - Answer: - λ-calculus is a formal system in Mathematical Logic -Natural numbers (0, 1, 2, ....) are defined as functions in λ−calculus.
a. ≡ (λwyx.y(wyx))(λsz.s(sz)) ≡ (λyx.y((λsz.s(s(z))) ≡ (λyx.y(y(y(x))) ≡ 3 b. ≡ (λwyx.y(wyx))(λsz.s(sz)) ≡ (λyx.y((λsz.s(s(z))) ≡ (λyx.y(y(y(x))) ≡ 3 c. ≡ (λxyz.x(yz))2 2 ≡ (λz.2(2z)) ≡ 4 Scheme Language - Answer: •One of two dialects of LISP language (the other one is Common Lisp) •It is a functional programming language •It was developed at the MIT AI Lab by Guy Steele and Gerald Gussman. •The language is case insensitive •Its theoretical foundation is Lambda-calculus •It uses recursion heavily •It uses prefix convention •There is no iteration in Scheme. You have to use recursion to implement iteration
•"hello" →"hello"
(3) Write code to get the third element of a list. You code must be able to apply to the list '(a b c d e) and return c. (4) Write code to get the list that removes the first two items of the input argument. In other words, you code must be applied to '(a b c d) and return (c d). (5) Write code to define fibonacci function: f(0) = 0, f(1)=1, f(2)=f(1)+f(0), f(3)=f(2)+f(1) ..... (6) Write a function that accept low and high as input and print from low to high (include both low and high). For example, if low is 4, high is 7, your program should print 4, 5, 6, 7. - Answer: (1) (+ 3(*4 (- 5 6))) (2) (define (solve-equation x) (define a (^ 4x + 2 - 3x 6) (display a)) (3) (define (third list) (map (map cadr list)) (4) (define delete (lambda (item list) (cond ((equal? Item (car list) (cdr list))
(else (cons (car list) (delete item (cdr list))))))) (5) (define fibonacci n) (if (< n 2) n (+ fibonacci (- n 1)) (fibonacci (- n 2))))) (6) (define func (low, high) (cond (< low high) (display "low < high") (newline) (do ((nums (list low)) (i 0 (+ i 1))) ((= i low) num) (numlist! num i i)) (display numlist) (newline) (else (display "high > low")))