Hi,
I ran a test of your filter example and got 1|3|_
Maybe you did something strange?
/pavel

On Tue, 18 Dec 2007 17:19:20 +0100, Torsten Anders <[EMAIL PROTECTED]> wrote:

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


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

Reply via email to