Raphael Collet a écrit :
Dear Oliver,

The '|' operator is not a function in the Oz sense. As Torsten pointed out, this operator is a shortcut to building tuples: A|B is translated by the compiler into '|'(A B).
There is a good reason for '|', '#', 'andthen' and 'orelse' (at least) to not be functions. They play tricks with the evaluation order. It is obvious for 'andthen' and 'orelse' that may not evaluate their second argument at all. It is less obvious for the record constructions but they actually expand their operands *after* their result. In most cases this is completely transparent and gives more opportunities for tail-call optimisation but the transparency can break when used with some non-dataflow constructs.
Here is an example:

\undef USE_CONS_FUNCTION
% Uncomment next line to try with a Cons function
%\define USE_CONS_FUNCTION
declare
fun{Cons A B} A|B end
fun{SlowIdentity X}
    {Delay 1000}
    X
end
TheCons
thread
\ifdef USE_CONS_FUNCTION
  TheCons={Cons {SlowIdentity foo} {SlowIdentity bar}}
\else
  TheCons={SlowIdentity foo}|{SlowIdentity bar}
\endif
end
{Browse {IsFree TheCons.1}}

Cheers,
Yves

Using Fold or Map with a function like "fun{$ A B} A|B end" is what we usually do ourselves. And there's nothing wrong with it ;-)

Cheers,
Raphael

On Sun, Feb 7, 2010 at 6:45 PM, Oliver Mooney <[email protected] <mailto:[email protected]>> wrote:

    Hi all,

    How do I refer to the cons function or | operator to use it in a
    fold or map? I can always wrap it in a function like:

    fun {MyCons A B} A|B end

    but I don't see how to refer to the | directly (like I can to +
    using Number.'+' for example).

    Thanks,
    Oliver.

    
_________________________________________________________________________________
mozart-users mailing list [email protected] <mailto:[email protected]>
    http://www.mozart-oz.org/mailman/listinfo/mozart-users



------------------------------------------------------------------------

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to