1.0 Introduction Flashcards
What does {…} mean?
Used for procedure- and function calls
What des {Browse X} do?
Open browser window with content of X
Describe an Oz variable
Variables has 2 components, an identifier and a store variable.
Identifier: Name, start with uppercase letter
Store variable: Part of system’s memory. Declare creates a new store variable, and makes identifier point to it.
Must be declared.
Values are bound to variables. Once a variable is assigned a value, it can not change.
declare
A = 10
Variables later in the program can have the same name as a previous variable. In this case, the old value will be overwritten, and cannot be accessed again.
Variables/calculations done with the previous variable-value will remain the same. This is because the identifier just refers to a new store variable, not overwriting the previous one.
Describe an Oz function?
declare
fun {FunName X}
declare: Creates new variable FunName
fun: Statement, defines a function
FunName: Bound to this function
What is functional abstraction?
When functions are used to define other functions.
declare
fun {Fun2 X Y}
{Fun1 X Y}
end
Define lists in OZ
List contains 2 things:
- Head-element
- reference to the rest of the list (Tail-list)
Can create a list by adding Head-elements:
a = nil
b = 1|a
c = 2|b
Fetch list components:
L.1: Gives list head-element
L.2: Gives reference to rest of the list
What is consing?
Cons (or a pair): The link H|T
Consing: Creating a new link
If T is a list. Consing H and T creates the new list H|T
Describe Oz pattern matching
case List of H|T then S end
case: Declares 2 local variables and binds them to the Head and Tail of the list.
case decomposes the list List based on the pattern H|T
What is language semantics?
A mathematical model of the operations of a prorgamming language, defining what the operations should do
What is program specifications?
What a program should do.
The mathematical definitions of input provided to the program and output it calculates..
How to declare local variables within if-else statements?
if condition then
// block
else L in
L = 5
end
What is a program’s time complexity?
Execution time as function of input size, up to a constant factor.
What is lazy evaluation?
Only doing a calculation when the result is needed.
fun lacy {Count N}
N | {Count N+1}
end
lazy: function will only be evaluated when needed
What does <future> mean when returned by a Browse function?</future>
That the variable has a lazy function attached to it.
How can you access values returned from a lazy function?
Values will only be calculated when needed.
L = {Count N} // Here Count is a lazy function
{Browse L}: returns L<future></future>
{Browse L.1}: returns first element of L
case L of A|B|C|_ thn {Browse A + B + C} end
Here the first three values of L is needed, therefor they are calculated
What is higher order programming?
Functions that takes other functions as argument
declare
fun {HigherOrder Op X}
{Op X}
end
What is concurrency?
When programs consist of several independent activities that operate at their own pace. The programmer specifies communication between these.
What is a thread, and how are they created?
An executing program.
Program can contain multiple threads.
thread
{Browse ‘hello’}
end
What is dataflow behaviour?
If a function tries to access a variable that is not yet bound, the program waits until this variable gets bound, maybe by another thread running.
What is dataflow concurrency?
Programs with dataflow behaviour will always produce the same results, however operations and bounding is partitioned between threads.
As long as the same operations are performed, with the same arguments, their behaviour remains the same.
What is an object and an objects interface?
A function with internal state.
The interface of an object is the functions defined within it.
declare
local C in
C = 1
fun {Fun1}
return 1
end
fun {Fun2}
return 2
end
end
What is the difference between object based- and object oriented programming?
Both use classes and objects, but object-oriented also implement inheritance.
What is nondeterminism?
Threads operate independently. Because of this they may operate in different orders in different program runs, leading to different program outputs (race condition)
What does it mean that threads are interleaving?
They take turn executing a little bit of their programs at the time. Meaning, when one thread is scheduled, it may not run to completion, when the next is scheduled.