functional replace function?
[1/5] from: bry:itnisk at: 1-Nov-2002 10:53
I suppose this is possible but my Rebol is not good enough yet to see
the solution, (I say suppose because I am also worried that my mode of
thinking about the problem is colored by other languages)
I want to have two blocks, one block contains values to replace in a
string, the other block contains values that will be replaced
These values should be accessed from a function which I run against the
string. The string comes out the other end with values replaced.
This seems to me to be the smarter(more functional) structure,
unfortunately can't quite see my way to implementing it.
The dumber structure, which I can see but don't want to do cause it
seems dumber,
Would be to iterate through the block of values to be replaced, with
each iteration get the answering index number from the block of values
that shall do the replacing and then run it against the string
replace/all string val1 val2
block1: next block1
any suggested readings, links?
[2/5] from: g:santilli:tiscalinet:it at: 1-Nov-2002 12:07
Hi bryan,
On Friday, November 1, 2002, 10:53:53 AM, you wrote:
b> any suggested readings, links?
What about something like:
replace-many: func [
string
block
] [
foreach [src rep] block [
replace/all string src rep
]
string
]
>> replace-many "A word where some strings have to be replaced." ["word" "string" "strings"
"words" "to be" "been"]
== "A string where some words have been replaced."
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[3/5] from: carl::cybercraft::co::nz at: 2-Nov-2002 0:15
On 01-Nov-02, bryan wrote:
> I suppose this is possible but my Rebol is not good enough yet to
> see the solution, (I say suppose because I am also worried that my
<<quoted lines omitted: 14>>
> block1: next block1
> any suggested readings, links?
Hi Bryan,
It's late for me to attempt an example, but the reading I'd suggest
would be on parsing. See...
http://www.rebol.com/docs/core23/rebolcore-15.html
Not that iteration wouldn't work, but parsing may be faster.
--
Carl Read
[4/5] from: bry:itnisk at: 1-Nov-2002 13:02
Gabriele Santilli wrote:
> replace-many: func [
> string
<<quoted lines omitted: 5>>
> string
> ]
Thanks, that was very helpful, also in showing how to think about these
kinds of problems in Rebol.
[5/5] from: greggirwin:mindspring at: 1-Nov-2002 11:54
Hi Bryan,
<< (I say suppose because I am also worried that my mode of
thinking about the problem is colored by other languages) >>
I've been REBOLing for a little over a year now and my thinking still
prevents me from seeing good REBOLish solutions more often than I care to
admit. :)
Fortunately, the kind and generous folks on this list always seem to be
there to help.
--Gregg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted