Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: removing a character with replace - was: RE: [REBOL]

From: louisaturk:coxinet at: 6-Nov-2002 22:37

Anton, At 12:50 PM 11/7/2002 +1100, you wrote:
>You need to analyze, Louis! :) >Break the problem down. > > > I just tested again. At the console I get: > > > > >> x: ["aaaaaaa string"] > > == ["aaaaaaa string"] > > >> replace/all x "a" "s" > > == ["aaaaaaa string"] > > >> x > > == ["aaaaaaa string"] > > >> replace/all first "a" "s" > > >> x: ["aaaaaaa string"] > > == "sssssss string" > >I don't believe you. :) >That should be > > replace/all first x "a" "s"
Sorry, I probably copied a mistyped line. Actually, I'm not sure what I did. I stayed up too late trying to meet a deadline. It never pays off. My brain starts slipping out of gear when I get too sleepy. :>)
>'replace takes three arguments. >I will use parentheses to see clearly the >first argument to replace: > > replace/all (first x) "a" "s" > >The two lines of code above are equivalent. >If you want to see what first x is, use probe: > > replace/all (probe first x) "a" "s" > >or > > probe first x > replace/all first x "a" "s" > > > However, this script doesn't work: > > > > rebol [] > > x: ["aaaaaaa string" "what is an apple good for"] > > > > foreach l x [ > > replace/all first l "a" "s" > > ] > > > > ** Script Error: replace expected target argument of type: series > > ** Near: replace/all first l "a" "s" > > > > But without first it works. What is happening? > > > > Louis > >foreach creates the nice situation where, each iteration >through the loop, 'l is set to: > > first x > second x > >so you already have what you want.
Ok, this is what was confusing me. I remember now reading that foreach provided this feature.
>I recommend using ?? and 'probe again: > > foreach l x [ > ?? l ; <---- here you can see the value of 'l > probe first l ; <---- let's just see what we would get... > replace/all l "a" "s" > ?? l ; <---- here is the result > ] > >Anton.
I didn't know about ?? It will be useful for debugging. Many thanks for explaining. Louis