Lecture 8 Flashcards
What is a tuple?
A data type similar to a record, but elements are not named.
How do you create a tuple in Python?
Using tuple literals: myTuple = (3, 5.8, ‘apple’).
How do you access the first element of a tuple in ML?
Using #1(myTuple).
How do you assign a tuple pattern in F#?
let a, b, c = tup.
How are lists represented in LISP and Scheme?
Delimited by parentheses, no commas: (A B C D).
What does the CAR function do in Scheme?
Returns the first element of its list parameter.
How do you add an element to a list in ML?
Using ::, e.g., 3 :: [5, 7, 9].
How are lists created in Python?
With assignments: myList = [3, 5.8, “grape”].
What is a union type?
A type whose variables can store different type values at different times.
What is a discriminated union?
A union type with a type indicator (discriminant) for type safety.
How does Ada ensure type safety in unions?
By using discriminants in record definitions.
What are the fundamental operations for pointers?
Assignment and dereferencing.
What is a dangling pointer?
A pointer that references a deallocated heap-dynamic variable.
How does Java handle pointers?
Java replaces pointers with references to ensure safety.
What is type checking?
Ensuring that operands of an operator are of compatible types.