Concepts of Programming Languages

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

Map each of the following languages to the corresponding implementation mechanism. (a) C (b) C++ (c) Java (d) JavaScript (1) Compiled (e) Perl (f) Fortran (2) Interpreted (g) Python (h) Lisp (i) PHP

(1) --- a b c f (2) d e g h i

Match the following language features with the programming paradigms. A.Creating new variables B Variable assignment (1) Functional Programming C Use recursive functions D Use loops (2) Imperative Programming E machine efficiency F programming flexibility (3) Object-oriented Prog G modularity and program reusability

(1) --- A C F (2) --- A B D E (3) ---- F G

Map the following languages to their corresponding paradigms (a) C (b) C++ (1) Functional (c) Java (d) JavaScript (2) imperative (e) Perl (f) Fortran (3) Object-oriented (g) Python (h) Lisp (i) PHP

(1) --- d h (2) --- a b c d e f g i (3) --- b c d g i

2. Which of the following is the difference between an expression and a statement? (1)

(a) An expression has a value, while a statement does not;

Which of the following are higher order functions? (2)

(a) a function that takes another function as parameter (b) a function that returns another function as result

4. Lisp treats functions as first-class objects because it (5)

(a) allows function definitions to be nested (b) allows functions to be returned as result of other functions (c) allows anonymous functions to be used as expressions (d) allows functions to be passed as parameters to other functions (f) treats Functions as a type of built-in values All except: allows forward function declarations

1. Which of the following is not a feature of the Lisp programming language?

(e) Allows users to define their own types of data structures

Which of the following is NOT an example of type errors?

-A value intentionally casted to the wrong type -Converting an integer to a real (float) number

What does compile-time type checking do?3

-Allow a single type for each expression - Check for type consistency of each operator at compile time - Report where in source code the error is found

Which of the following type errors cannot be caught at compile time? 3

-An array being accessed out-of-bound - Null pointer dereference -Dividing a value by zero

Which of the following are must-have components of a type system? 4

-Basic types and their built-in operators -Compound types, their constructors, and operations to extract their values -Ways to determine whether two types are the same -Ways to check whether each operation is applied to the correct types

3. What can types be used for? 3

-Catch errors in the program early at compile time - Specialize efficient implementations of types at runtime - Help categorize the key concepts of programs into meaningful groups

What is type inference?3

-Does not require the types of variables being declared -. Automatically infers a single type for each expression -. Is done at compile time as a form of program analysis

What does runtime type checking do? 3

-Dynamically store the type of each value -Check the type of each value before operating on it - Catch all all type errors at runtime before they occur

Which of the following correctly define the type concept? 2

-Each type is a set of computable values -All values of the same type must have the same implementation

Which of the following is NOT correct about the ML type system? 2

-It allows the types of variables to be modified -Variables must be declared before used

How can ML pattern matching be used? 4

-It can be used in variable declarations and the case expressions - Different pattern branches must be alternative constructors of the same type - Variables used in patterns cannot have existed before - No variable in a pattern can appear more than once

How can ML pattern matching be used? 4

-It can be used in variable declarations and the case expressions - Different pattern branches must be alternative constructors of the same type -Variables used in patterns cannot have existed before -No variable in a pattern can appear more than once all except: It can be used only for ML datatype

What is the purpose of ML pattern matching?3

-It dynamically determines the constructor of a compound value - It initializes variables with components of a compound value -It provides an alternative way of declaring new variables all except: It modifies the values of existing variables

What is the purpose of ML pattern matching? 3

-It dynamically determines the constructor of a compound value -It initializes variables with components of a compound value -It provides an alternative way of declaring new variables

Which of the following correctly categorize the ML language? 4

-It is a compiled functional programming language - It is designed as a meta-language for logics of computable functions - It belongs to the Algol family and the Lisp family - It supports both functional and imperative programming All except: It requires variables to be declared before used

Which of the following correctly categorize the ML list type?3

-It works the same as lists in Lisp but can contain only elements of a single type - Similar to C arrays, it serves as a container that can be made arbitrarily long at runtime. -The values of a ML list cannot be modified

Which of the following correctly categorize the Algol family of languages (which include C)? 4

-They belong to the imperative programming paradigm -They modify variables using blocks of statements and loops -They are compiled and allows only a single type for each variable -They allow users to define new compound types all except: They prevent all type errors at compile time

Which of the following are optional components of a type system?2

-Ways to introduce new types not already in the system -Ways to convert one type to another

Which of the following defines or correctly categorizes the halting problem?

-Whether an arbitrary program can halt eventually when given an arbitrary input - The halting problem is not solvable (i.e., not computable by computers)

Which of the following is NOT an example of meta programming?

Use Shell scripts to invoke compiled C programs

Categorize the following as a feature of either high-level or low-level programming languages A code runs faster on hardware B easy to write and maintain (1) High level C easy to port to different machines D easy to debug (and detect errors) (2) Low Level E easy for human to understand F easy for machine translation

(1) --- B C D E (2) --- A F

What is the difference between the pure and the applied lambda calculus?

The applied lambda calculus includes more pre-defined values

Select criteria for deciding whether a language should be implemented using a compiler or an interpreter

-Whether the language allows each variable to have arbitrary types at runtime D. Whether the language implementation needs to be fast E. Whether the program needs to be used more than once F. Whether the language needs to support large scale software development

Which of the following type errors can be caught at compile time? 2

-adding an integer with a string -A value being casted to an unrelated type

1. A Lisp program may include which of the following as the sole component?

-an expression -a variable definition

What type equivalence is used for the following C types? (a) array (b) pointer (c) struct (d) int

-array, pointer, int: use structural equivalence -struct: use name equivalence (two types are different unless given the same name)

3.The advantages of functional programming without modifications are (2)

-complex data structures can be shared without unexpected side effects -computations can be parallelized without unexpected interactions among threads

To maintain memory consistency, which of the following should not be allowed? (a) jumping into the middle of a block (b) jumping out from the middle of a block (c) partially overlapping two blocks with each other

-jumping into the middle of a block - partially overlapping two blocks with each other

Which of the following are not allowed in pure functional programming

-variable modifications - loops

7. What is the biggest difference between a compiled language and an interpreted language?

A compiler does not run the program --- instead it translates the program into a representation in a lower-level language (e.g., assembly or machine code)

What is the difference between a transparent and an opaque type declaration?

A transparent declaration introduces a synonym for an existing type; an opaque one introduces a new compound type that didn't exist before

Which of the following are key programming concepts modeled by Lambda Calculus?

A. Symbolic evaluation of function abstractions and applications C. Reasoning of program equivalence

Select criteria for deciding whether a language implementation uses a compiler or an interpreter.

A. Whether the implementation produces an object code equivalent to the original program B. Whether program input data is required for the compiler or interpreter to work

Decide whether each of the following features is an advantage of compilers or interpreters. A. Generated code can run many times B Can afford heavy weight optimizations C Can pre-examine program for errors before runtime D Have full knowledge of program input E Can easily adapt program behavior dynamically

Advantages of compilers: ABC Advantages of interpreters: DE

Which of the following statements are correct about the Lisp interpreter? (a) It dynamically allocates a new cons cell each time the cons operator is invoked (b) It dynamically allocates a new cons cell each time a symbol or a number is used (c) It invokes the garbage collector to reclaim memory when running out of the cons cells (d) It only reclaims cons cells that are no longer reachable from the user program (e) Each list is represented using the address of a cons cell.

All except: (b) It dynamically allocates a new cons cell each time a symbol or a number is used

What is polymorphism?

Allowing operators to operate on multiple types of values

Which of the following problems are computable (can be fully solved by computers)? Which are not computable? A. The halting problem B. Translating arbitrary Java programs to C. C. Whether a sorting program is implemented correctly. D. Whether an arbitrary program is free of bugs.

B, C are computable; A, D are not computable.

Which of the following is an example of reflective programming?

Build a Lisp expression as a list and then invoke the eval command to interpret it

ad hoc polymorphism

Different implementations for different types

4. Decide whether each of the following components belongs to a compiler or interpreter (or both). A lexical analyzer B syntax analyzer C semantic analyzer D intermediate code generator E code optimizer F machine code generator

Components of compilers: ABCDEF Components of interpreters: ABC

2.Categorize each of the programming mechanisms into the following paradigms: Functional Programming Imperative Programming Object-oriented programming

Functional: recursion and functions as pointers imperative: loops OO programming: encapsulation

What is the difference between structural and name equivalence of types?

In structural equivalence, two types are the same if they have the same components; in name equivalence, two types are the same if they have the same name.

Which of the following defines the normal form of lambda calculus?

It cannot be reduced any more

Given a BNF, e ::= n | e+e | e-e | e * e | (e) which describes the syntax of expressions, identify the following components of the BNF: Non-Terminals (Variables representing concepts): Terminals (Vocabulary of the language): Start Non-Terminal (The top-level concept of a language): Productions (Rules of composing the language):

Non-Terminals (Variables representing concepts): e Terminals (Vocabulary of the language): n + - * ( ) Start Non-Terminal (The top-level concept of a language): e Productions (Rules of composing the language): e::=n; e::=e+e; e::=e-e; e::=e*e; e ::= (e)

parametric polymorphism

Parameterizing implementations with type parameters

Which of the following explains the confluence of lambda calculus?

The normal form of a lambda calculus term, if exists, is unique

Which of the following about lists in Lisp are false?

They cannot be built incrementally (e) They cannot be given names

Which of the following about lists in Lisp are true?

They may contain arbitrary types of elements (b) They are singly linked lists (c) They can be nested and thus become trees

Which of the following correctly defines a block?

a fragment of code that introduces new variables

Which of the following correctly distinguish basic types from compound ones?

a. Values of basic types cannot be decomposed, while those of compound types can.

Which of the following are components of the Lisp Abstract Machine? (a) The current Lisp expression to evaluate (b) The continuation of computation after the Lisp expression (c) A table that remembers the values of all variables (d) a collection of memory for dynamic allocation (cons cells) (e) A garbage collector (f) The syntax of the Lisp language and its parser

all except: A garbage collector (f) The syntax of the Lisp language and its parser

Which of the following is NOT a component of the runtime machine model of a compiled language? (a) runtime stack (b) heap (c) the code space (d) the program counter (e) syntax analysis

all except: syntax analysis

Heap stores

dynamically allocated memory

Code space stores

instructions of the program

Which of the following languages are type safe? (a) C (b) C++ (d) Java (e) Javascript (f) ML (g) Lisp

java javascript ML Lisp

Most general programming languages are Turing complete and can express all functions that are

partial recursive

Which of the following C types most closely resembles the ref type in ML?

pointer

code pointer stores

the next statement to evaluate

Which of the following C types most closely resembles the datatype in ML?

union

Runtime stack stores

values of variables


Kaugnay na mga set ng pag-aaral

PrepU: Fluid, Electrolytes, and Acid-Base

View Set

BYU Fitness For Living Well Final

View Set

Content Quiz 7: Inventory Management (Module 7)

View Set

Kaplan Physics/Math Review Vocab, Master vocab list

View Set