<< Prev | - Up - | Next >> |
Internally, Oz supports only a single kind of procedures which are all relational. The idea is that -ary functions are treated as
-ary relations. This can be observed in the Browser:
declare Square = fun{$ X} X*X end
{Inspect ['Browsing fun{$ X} X*X end yields <P/2>' Square]}
{Inspect {Square 111}}
When browsing the value of procedure named Square
a string is displayed meaning that the value of Square
is relational procedure with 2 arguments rather than a functional procedure with a single argument. The additional argument is used for the output.
Note also that the expression {Square 111}
denotes a value, wheres {Browse 111}
has none. The reason is that Browse
denotes a relational procedure which in contrast to a functional procedure does not return a output value.
As said already, the output behaviour of a functional procedure can be simulated by a relational procedure which raises a side effect on a logic variable (see section unification). In fact, Oz supports functional procedure through relational procedures. A functional procedure with arguments is translated into a relational procedure with
arguments, where the last arguments serves as an output argument. For instance, the functional procedure
fun{Square X} X*X end
and its application Y={Square 3}
are translated as follows:
fun{Square X} X*X end ==> proc{Square X Out} Out=X*X end
declare Y={Square 3} ==> declare Y in {Square 3 Y}
The translation introduces a free logic variable Y
that is passed as an additional argument to the application {Square 3 Y}
. The application is then executed; once it finishes it computation, it binds the logical variable Y
to the functional result 9
. The result is thus passed by a side effect on a logic variables.
<< Prev | - Up - | Next >> |