Sorry for the noise -- it works on my machine as well :)

After some head scratching I realised that, when I simplified some of my code to prepare my question, I also took out some mistake of mine (and then I didn't double-check the code of my question..).

So, sorry again.

Best
Torsten

On Dec 18, 2007, at 4:46 PM, Wolfgang Meyer wrote:
On my system (Mozart Engine 1.3.1 (20040617) on Windows XP) the code snippet behaves as expected by you: the Browser displays "1|3|_".

This is the case even if I include the definition of Filter in the source code.

Maybe a version issue? I'll try this at home on a newer Mozart version later today.

Wolfgang


Dear all,

I don't fully understand the behaviour of Filter in concurrent
programming. List.filter is defined as follows

fun {Filter Xs F}
    case Xs of nil then nil
    [] X|Xr then if {F X} then X|{Filter Xr F}
    else {Filter Xr F} end
    end
end

I would expect that this definition works even for partly determined
Xs (i.e. as far as Xs is determined). For example, I expect the code
below to immediately show in the browser the following: 1|3|_

declare
Xs = [1 2 3 _ 4]
Ys
thread Ys = {Filter Xs IsOdd} end
{Browse Ys}

However, Filter blocks until Xs is fully determined. Why is this so?
By contrast, things like Map and ForAll use a very similar case
statement in their definition (but without an else clause) and they
work fine for partially determined lists.

Thank you!

Best
Torsten

BTW: I needed a variant of filter which returns/skips list elements
as soon as enough information is provided to decided either way, but
possibly changes the order of list elements:

proc {UnorderedFilter Xs F ?Result}
    P = {NewPort Result}
in
    {ForAll Xs proc {$ X}
               thread
                  if {F X} then {Send P X} end
               end
            end}
end

--
Torsten Anders
Interdisciplinary Centre for Computer Music Research
University of Plymouth
Office: +44-1752-233667
Private: +44-1752-558917
http://strasheela.sourceforge.net
http://www.torsten-anders.de




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

Reply via email to