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: anton:lexicon at: 7-Nov-2002 12:50

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" '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. 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.