[m-users.] spawn in Rosettacode
Peter Ross
peter at emailross.com
Fri Aug 29 13:35:55 AEST 2014
Hi Robert,
On 29 August 2014 13:29, Robert Smart <robert.kenneth.smart at gmail.com> wrote:
> At http://rosettacode.org/wiki/Concurrent_computing#Mercury, we see:
>
> main(!IO) :-
> spawn(io.print_cc("Enjoy\n"), !IO),
> spawn(io.print_cc("Rosetta\n"), !IO),
> spawn(io.print_cc("Code\n"), !IO).
>
> It is a bit hard to understand how this could work. My beginner's
> understanding would be that the 2nd spawn couldn't happen till the first had
> produced the new world that is its input parameter. Etc.
>
> And my compilation of it (on OSX) produces the outputs in the same order as
> in the program every time.
>
> It is interesting to consider how languages which explicitly thread IO (like
> Haskell and Mercury) should handle multiple interactions with the world
> where the order doesn't matter, so that concurrency can be done implicitly
> or explicitly.
>
Mercury handles this by the determinism, it's not det but cc_multi
(committed choice multi). cc_multi means that there are 1 or more
solutions (multi) but the compiler will commit to only one of those
solutions (cc - committed choice).
A det program on the other hand says there is only one solution, so
you would always get the results in the same order.
Regards,
Pete
More information about the users
mailing list