[REBOL] Re: replace
From: jelinem1:nationwide at: 26-Jun-2001 17:16
Let's forget that no replace function - in any language that I've ever
used - will ever generate an error upon "zero replacements", and build one
that makes the most sense. If REBOL 'replace were to generate an error
under this condition, then - as Anton pointed out - you would have to wrap
every ARBITRARY call to 'replace with a 'try structure or use an "if find"
statement to ensure that the search string exists in the parent string.
IMO this goes against the principle of making simple tasks simple. If you
really want to trap the case where the search string does not exist in the
parent string, this really echoes the functionality of 'find (again, Anton
gave an example of this, below).
If you really want to change the behaviour of 'replace, feel free to
redefine it. Do a "source replace". Copy the code and modify it. "Have it
YOUR way!" :)
- Michael Jelinek
From: [ryan--christiansen--intellisol--com]@rebol.com on 06/26/2001 03:32 PM
Please respond to [rebol-list--rebol--com]
Sent by: [rebol-bounce--rebol--com]
Subject: [REBOL] Re: replace
But... shouldn't replace return an error, anyway, if you are asking it to
replace something that doesn't exist?
<[arolls--bigpo] To: <[rebol-list--rebol--com]>
Sent by: Subject: [REBOL] Re: replace
Just do this:
either find a c [replace a c c][
;it wasn't found
or even (if a is long)
either t: find a c [replace t c c]
Just think, you would have to couch each
'replace with an
either error? try  structure.