[Find] Frustration with Find
[1/4] from: pwawood:mango:my at: 1-Nov-2004 9:10
I'm finding the behaviour of 'find to be a little counter intuitive.
When the value being searched for isn't found find returns none! rather
than the tail of the index.
I wanted to code like :
str: "abcde"
if not tail? str: find str "1" [......]
However this throws up a script error as the value of str is set to
none! and it is now "disconnected" from the series!
>> str: "abcde"
== "abcde"
if not tail? str: find str "1" [......]
** Script Error: tail? expected series argument of type: series port
bitset
** Near: if not tail? str: find
>> type? str
== none!
I'd appreciate any comments and insight on why find returns a none!
value in these circumstances?
Regards
Peter
[2/4] from: carl::cybercraft::co::nz at: 1-Nov-2004 7:47
On Monday, 1-Novenber-2004 at 9:10:35 you wrote,
>I'm finding the behaviour of 'find to be a little counter intuitive.
>When the value being searched for isn't found find returns none! rather
<<quoted lines omitted: 14>>
>I'd appreciate any comments and insight on why find returns a none!
>value in these circumstances?
A none!'s returned because nothing was found perhaps? :-)
My approach would be to use something like this...
>> str: "abcde"
== "abcde"
>> if found: find str "1" [str: found "etc..."] probe str
abcde
== "abcde"
>> if found: find str "c" [str: found "etc..."] probe str
cde
== "cde"
Requires the creation of another word, but the code itself looks a little tidier (in
my opinion, at least.)
-- Carl Read.
[3/4] from: SunandaDH:aol at: 1-Nov-2004 4:24
Peter:
> However this throws up a script error as the value of str is set to
> none! and it is now "disconnected" from the series!
I think the issue is that matching the tail of a string is not the same as
not matching any part of it.
(find "abcde" "x") = tail "abcde"
So find can't return any part of the string in the case of a failure. Hence
the none as the response.
If you do want to position at the tail of the string when not found, you
could make a function out of this:
str: "abcde"
either temp: find head str "c" [str: temp] [str: tail str]
(You won't want the 'head if you want to search from the current position)
Sunanda.
[4/4] from: pwawood::mango::net::my at: 1-Nov-2004 17:52
Carl & Sunanda
Thanks for the suggestions and explanations. I was trying to avoid
using an additional word but it seems that cannot be avoided. I suppose
I shouldn't worry too much because a word is small and I don't need to
duplicate the underlying value.
Peter
On Monday, Nov 1, 2004, at 17:24 Asia/Kuala_Lumpur, [SunandaDH--aol--com]
wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted