<< Prev | - Up - | Next >> |
An Oz variable describes a value of an arbitrary type. Variables in Oz are logic variable whose value cannot cannot be changed.
The Oz programming interface comes with a lot of predefined global variables such as List
and Number
. The values of both variables are records containing the standard functions for lists and numbers. For instance, a procedure for multiplication Number.'*'
can be selected from the record Number
at feature '*'
. The expression X*X
in turn is nothing else than syntactic sugar for the application {Number.'*' X X}
.
Local variables can be introduced in Oz by using expression of the form local ... in ... end
. The following expressions describes a record which contains two numbers, the squares of 3 and 4.
local
Square = fun{$ X} X*X end
in
record(s3:{Square 3} s4:{Square 4})
end
The scope of a local variable is restricted by the local-end-expression in which its is introduced. For instance, the local variable Square
cannot be accessed any further.
Note that local
constructs can not only be used to form statments rather then expressions:
local
X = 3*4
in
{Browse X*X+5}
end
This statement shows a value rather but does not describe any.
<< Prev | - Up - | Next >> |