Lecture 4 Flashcards
What is a type?
Set of values together with a set of operations on these values.
Example:
Integers: integer numbers + add, sub, div, mul
What is static type checking?
Performed before execution, at compile-time
What is dynamic type checking?
Run-time type checking.
Performed during execution, before execution of each individual operation.
How is a practical language defined from the kernel language?
Add syntactic sugar and linguistic abstractions.
Syntactic sugar: Syntactic conveniences for commonly used functionality.
Linguistic abstractions: Syntactic conveniences that introduce new programming structures without extending the model of computation.
Give 2 examples of syntactic sugar
Nested records:
Z = z(y: y(x: 1))
Multiple variable declaration:
local X Y Z in <s> end</s>
How can record features be accessed using pattern matching?
case E of label(feature2: value anotherFeature: value4) then
X = value
Y = value4
end
What does _ mean in:
case R of label(f1:_ f2:value) then
(‘_’) denotes an unnamed variable, used to keep values we do not care about.
What syntactic sugar makes it easier to access record fields?
A = recordName(feature: value)
X = A.feature
What does Record.arity return?
List of features
What is a keyword?
A lexeme that has some special meaning, may be related to syntactic and semantic rules
What are reserved words?
Lexems that can only be used as keywords.
What is an atom?
Atom start with lowercase, and any variables/symbols after that
Atom can be any lexem in quotes matching ‘[^`\]’
A record with no fields:
atom == atom()
Syntactically, atom is not equivalent to atom()
What is an identifier?
A syntactic entity, part of programs sequence of tokens
Identifier mapped to variable.
Variable bound to value.
What is a variable?
A semantic entity, part of the execution of a program.
What are declarative variables?
After initial binding, they cannot be reassigned another value.
Dataflow variables.
What are partial values?
Can contain unbound variables, e.g. records.
declare X Y in
Y = label(feature: X)
Why does Browse not belong to the declarative sequential model of computation?
It starts a new thread in which the browser displays a value
What is an expression?
An operation that evaluates to a value.
Examples:
2+2 (evaluates to 4)
A == B (evaluates to true or false)
proc {$ X} X = 1 end (evaluates to a procedure)
What is a statement?
Specifies an operation that does not evaluate to a value.
X=1 (unifies X with 1)
{Browse ‘hello’}
skip
Define a program in the declarative sequential kernel language in regards to statements and expressions
A program composed exclusively of statements
Give an example of if-else constructs being a statement and an expression
Statement:
local X in
if A > B then
X=A
end
end
Expression:
if A > B then
A
end
What is a function?
Linguistic abstractions of procedures.
A function definition can be translated into a procedure.
Function of n arguments is a procedure of n + 1
What does # mean?
It is the tupling constructor.
Syntactic sugar for building records.
X#Y#Z equals ‘#’(X Y Z)
Instead of X == 1 andthen X==2 andthen X== 3 then <s> end</s>
We can pattern match:
case X#Y#Z of 1#2#3 then <s> end</s>
What is a list?
A sequence of records.
The record that form a list has the label ‘|’ and 2 features (1: Head and 2: Holds tail list)
[one two]
= ‘|’ (one ‘|’ (two nil))
= one|two|nil