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

[REBOL] find/last/part behaviour

From: andreas::bolka::gmx::net at: 22-Dec-2002 1:53

I noted a quite odd behaviour of 'find when combining /last and /part refinements - at least it is not what I expected. Basically I wanted to achieve "ends with" functionality - some examples to illustrate the desired behaviour: ends-with? "1234567890" "890" ; == true ends-with? "1234567890" "0" ; == true ends-with? "1234567890" "9" ; == false Now I thought that combining the /tail and /part refinements of 'find would naturally map to this: /part -- Limits the search to a given length or position. range -- (Type: number series port) /last -- Backwards from end of string. /reverse -- Backwards from the current position Silly me, it seems, as internal 'find priorities make /part limit the string to be searched _first_ and then search backwards within that string. Which leads to the following: found? find/last/part "1234567890" "890" 3 ; == false If you agree that /part should have a "higher priority" than /last, this behaviour is what would be desired. However, there is a solution to achieve what was desired. Combine /reverse and /part and use 'tail up-front: found? find/reverse/part tail "1234567890" "890" 3 ; == true And it is this notion, that /reverse has a "higher priority" than /part while /last has not, that I don't think is consistent. Any ideas how this consistency problem could be resolved? Is it a problem at all? -- Best regards, Andreas mailto:[andreas--bolka--gmx--net]