On 11/26/05, Benjamin L. Russell <[EMAIL PROTECTED]> wrote:
> SMerge is declared as a procedure with the three
> arguments Xs, Ys, and Zs, yet when invoked in the line
>
> > Zs = X|{SMerge Xr Ys}
>
> with only the two arguments Xr and Ys, no illegal
> arity error is generated. Why not?
Because that is syntactic sugar for something else. A procedure with N
arguments can be invoked with N-1 arguments, in a context where it is
being used as if it had a return value. The return value is the Nth
argument. proc{Times A B Z} Z=A*B end is equivalent to fun{Times A B}
A*B end, and in either case you can either say Y={Times 4 5} or {Times
4 5 Y}. In this case, your code is equivalent to
local Temp in
Z = X|Temp
{SMerge Xr Ys Temp}
end
(In the OPI, under the Oz menu, you can ask it to "Show Core Syntax"
and it will give you this same translation or one like it.) Thus, you
see that it really is a 3-ary procedure, so no arity error. Trying to
invoke {SMerge Xr Ys} alone *would* be an arity error, as there
wouldn't be any third argument. Effectively, unlike in C++ or Java,
you can't just "throw away" return values unless you do it explicitly.
IMHO, getting to throw away return values can be nice at times but
isn't worth all the syntactic pain that comes with it. Mozart's syntax
ends up being a lot cleaner, and it seems to be due in large part to
this.
Max Wilson
--
Be pretty if you are,
Be witty if you can,
But be cheerful if it kills you.
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users