[Oz] Oz and Python
Denys Duchier
Denys.Duchier at ps.uni-sb.de
Thu Jan 13 09:26:04 CET 2000
zorro at zipzap.ch (Borcis) writes:
> I really would like Oz with Python syntax, e.g. trading braces
> (or other sorts of parentheses) for indentation-specified blocks,
and others would like precisely the opposite as witnessed by the
recurring arguments about the semantic significance of white space in
Python. We will still be arguing about this when hell freezes over,
and no closer to a consensus :-)
> Another thing that I regret not to have in Oz, is Life's style
> and syntax of function definitions.
I am not going to argue about syntax, but just for comparison:
Life:
fact(0) -> 1.
fact(N:int) -> N*fact(N-1).
Oz:
fun {Fact N}
if N==0 then 1 else N*{Fact N} end
end
or
fun {Fact N}
case N of 0 then 1 else N*{Fact N} end
end
> But *functions definitions* are precisely where Life is more
> "concurrent constraints" than "logic programming", aren't they ?
I suspect that what you mean is that you like Life's idea of
residuations (i.e. function applications use a form of matching that
suspends until the argument is sufficiently instantiated). Indeed
Life was a pionneer in exploring this notion of entailment-based
synchronization. In Oz this is fully generalized to the notion of
entailment of nested computation spaces, i.e.:
cond <S1> then <S2> else <S3> end
executes <S1> in a nested computation space and suspends until this
space becomes either entailed or inconsistent, i.e. until the
condition can be decided one way or the other. However, for the
Life-style of function definitions the `case' statement often
suffices, e.g.:
Life:
foo(f(X X)) -> a.
foo(g(a)) -> b.
foo(g(b)) -> c.
foo(X) -> d(X).
Oz:
fun {Foo T}
case T
of f(X X) then a
[] g(a) then b
[] g(b) then c
else d(T) end
end
The Oz version will likewise suspend until the next alternative to be
considered can be shown to be either entailed or disentailed.
However, Life psi-terms offer direct support for sorts. In Oz, such a
sort hierarchy must be encoded, e.g. using FD variables and the same
down-set encoding technique used in Life (I have written libraries to
do this). Consider:
Life:
foo(X:s1) -> a.
foo(X:s2) -> b.
foo(X) -> c.
where s1 and s2 are sorts. Suppose in the Oz encoding s1 (resp. s2)
corresponds to domain D1 (resp. D2).
Oz:
fun {Foo X}
cond X::D1 then a
[] X::D2 then b
else c end
end
Here we need the more expensive `cond' statement that uses a nested
computation space to explore a guard. Note however that Life's
functional residuations are not as general as the concurrent
disjunctions supported by Oz:
or <A1> then <B1>
[] <A2> then <B2>
...
[] <An> then <Bn>
end
where all the guards are concurrently investigated, each in its own
nested computation space.
Cheers,
--
Dr. Denys Duchier Denys.Duchier at ps.uni-sb.de
Forschungsbereich Programmiersysteme (Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45 http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50 Phone: +49 681 302 5618
66041 Saarbruecken, Germany Fax: +49 681 302 5615
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
More information about the mozart-users
mailing list