On 4/30/06, Anthony Borla <[EMAIL PROTECTED]> wrote:
Greetings,

Playing around with Oz again [as well as finally reading through CTM - what
a mind blower !], and have a really quick query on regex use, specifically,
the correct use of 'Regex.replace'.

The documentation states that the 'Regex.replace' signature is as follows:

    {Regex.replace +TXT +RE +FUN ?RES}

'+TXT' and '+RE' are fairly obvious, but what is the signature of '+FUN'
supposed to be ? All my attempts [guesses, actually] have failed miserably,

FUN takes the text (TXT) and a match description and returns new text
to replace the matched text.

and the most 'successful' of these failed attempts simply blocks [presumably
waiting for a dataflow variable to bind ?]. A code excerpt follows:

    Seq = {NewCell nil} Cre = {NewCell nil}
    ...
    Seq := "abcde\n12345\nABCDE\n"
    Cre := {Regex.make "\n"}
    ...
    Seq := {Regex.replace @Seq @Cre fun {$ X Y} X end}

I presume that X is bound to "\n" [don't know about Y - is *it* waiting to
bind ?], and at present it is simply being returned [I actually want to
remove it, so this would mean replacing it with "" (?), but this does not
work].

I'm probably making a pretty fundamantal error, but this is truly driving me
nuts. If anyone has an explanation, or perhaps a short *working* example,
I'd very much appreciate it.


I don't know why your example is blocking.  It works for me.  Below is
a full example that should show you what is going on.

cheers
k

declare
[Regex] = {Module.link ['x-oz://contrib/regex']}

Seq = {NewCell nil} Cre = {NewCell nil}

Seq := "abcde\n12345\nABCDE\n"
Cre := {Regex.make "\n"}

Seq := {Regex.replace @Seq @Cre fun {$ X Y} {System.show o(x:X y:Y)} X end}

{System.show @Seq}

which outputs:

o(x:<ByteString "abcde\n12345\nABCDE\n"> y:match(0:5#6))
o(x:<ByteString "abcdeabcde\n12345\nABCDE\n12345\nABCDE\n"> y:match(0:28#29))
o(x:<ByteString
"abcdeabcde\n12345\nABCDE\n12345abcdeabcde\n12345\nABCDE\n12345\nABCDE\nABCDE\n">
y:match(0:68#69))
<ByteString 
"abcdeabcde\n12345\nABCDE\n12345abcdeabcde\n12345\nABCDE\n12345\nABCDE\nABCDEabcdeabcde\n12345\nABCDE\n12345abcdeabcde\n12345\nABCDE\n12345\nABCDE\nABCDE\n">

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

Reply via email to