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

[REBOL] Re: replace

From: joel:neely:fedex at: 26-Jun-2001 16:22

Hi, Ryan, Let me offer my reasons why I think there should not be an error: 1) If you care whether the substring occurs, you can test that condition yourself prior to attempting the REPLACE. 2) Many times one uses REPLACE (and especially REPLACE/ALL) in situations where the occurrence is optional. In such cases, one *wants* a function that does nothing gracefully. For example, I recently worked on a document management app that took user-supplied "topic" phrases and replaced spaces with underscores to create file names. Two examples of this replacement would be:
>> replace/all "my new topic" " " "_"
== "my_new_topic"
>> replace/all "testing" " " "_"
== "testing" (Of course, the first argument was supplied in a variable, but you get the idea.) The point is that the "eliminate whitespace" operation automatically succeeds in the trivial case when there is no whitespace to be eliminated. 3) The burden of additional coding should be on the exceptional case where one cares (1), rather than on the more common case where one does not (2), at least IMHO. -jn- [ryan--christiansen--intellisol--com] wrote:
> I was trying to use 'try on a block containing a 'replace > statement and couldn't understand why it would not return an error > when trying to replace a string that doesn't exist. I guess > 'replace simply doesn't error out. Why not? I think it should. >
> Please help me to understand 'replace. Why doesn't the following > return an error? > > >> a: "foobar" > == "foobar" > >> c: "fabulous" > == "fabulous" > >> replace a c c > == "foobar" > >>
-- It's turtles all the way down! joel'dot'neely'at'fedex'dot'com