1. Documentaion update request for "find"
- Posted by alanjohnoxley Sep 15, 2010
- 1196 views
Hi, the online docs for "find" don't seem to be correct:
9.3.2 Finding
9.3.2.1 find
<built-in> function find(object needle, sequence haystack, integer start)
Find the first occurrence of a "needle" as an element of a "haystack", starting from position "start"..
Looks like this is a "find_from" since it mentions the start position?
Also, this issue could have been mentioned too:
-- -- show the one level limitation of "find" function, -- and its derivatives such as find_from -- 15th Sept 2010 Euphoria v4.0 svn v3412 -- -- "find" will work on a one dimentional sequence only. -- sequence onedimentional, twodimentional onedimentional = {"one","two","three"} twodimentional = {{"one","two","three"}, {"four","five","six"}} procedure test() integer i1, i2 sequence arg, s1, s2 arg = "two" -- i1 = find(arg,onedimentional) s1 = sprintf("%1d",{i1}) -- i2 = find(arg,twodimentional) s2 = sprintf("%1d",{i2}) -- puts(1,"\nOne dimentional sequence find gave " & s1 & "\n") puts(1,"Two dimentional sequence find gave " & s2 & "\n") end procedure test()
"find" is working as designed; for the multi-dimentional find I would need to write my own routine that would return a sequence of nesting level and position.
Regards,
Alan
2. Re: Documentaion update request for "find"
- Posted by alanjohnoxley Sep 15, 2010
- 1171 views
How about "find" returning -1 if the searched sequence is not one-dimentional?
You may have guessed that I spent a lot of time on a bug where I expected to get a nonzero return from a find ! ;)
Regards,
Alan
3. Re: Documentaion update request for "find"
- Posted by ne1uno Sep 15, 2010
- 1125 views
Hi, the online docs for "find" don't seem to be correct:
9.3.2 Finding
9.3.2.1 find
<built-in> function find(object needle, sequence haystack, integer start)
Find the first occurrence of a "needle" as an element of a "haystack", starting from position "start"..
that appears to be a doc bug, the start param should be defaulted to 1 as per the description. the function signatures in the docs for the built-ins are not generated automatically from source and can be out of date.
4. Re: Documentaion update request for "find"
- Posted by SPringle Sep 15, 2010
- 1110 views
Buried in the documentation there is a find like function that does what you want in the standard library but I cannot remember its name or in which include file it is. We will be adding a table to help alleviate this problem. in the meantime, you might look at: w32findKey from the win32lib wrapper.
5. Re: Documentaion update request for "find"
- Posted by jimcbrown (admin) Sep 15, 2010
- 1095 views
"find" is working as designed; for the multi-dimentional find I would need to write my own routine that would return a sequence of nesting level and position.
Regards,
Alan
Buried in the documentation there is a find like function that does what you want in the standard library but I cannot remember its name or in which include file it is. We will be adding a table to help alleviate this problem. in the meantime, you might look at: w32findKey from the win32lib wrapper.
Yes, it is in std/search.e - find_nested() will do what is wanted.
How about "find" returning -1 if the searched sequence is not one-dimentional?
Regards,
Alan
No. Sometimes I want to do,
find("needle", {"a", "needle", "in", "a", "haystack"})
or even,
find("needle", {'a', "needle", {"in"}, "a", {"h", "aystack"})
find() works correctly with nested sequences. It just works differently than find_nested().
6. Re: Documentaion update request for "find"
- Posted by alanjohnoxley Sep 15, 2010
- 1101 views
Thanks Jim,
I'll use find_nested like you say.
However, if find returns -1 instead of 0, then the user would know what gives, especially if the -1 is documented?
I conceed it would break some existing code though, but only in places where the find scope is wrong anyway.
7. Re: Documentaion update request for "find"
- Posted by jimcbrown (admin) Sep 15, 2010
- 1093 views
However, if find returns -1 instead of 0, then the user would know what gives, especially if the -1 is documented?
I conceed it would break some existing code though, but only in places where the find scope is wrong anyway.
This is wrong.
find() works correctly, even on (especially on) nested sequences. Your change would break code that is using find() correctly with nested sequences.
8. Re: Documentaion update request for "find"
- Posted by alanjohnoxley Sep 15, 2010
- 1084 views
OK Jim,
I'll read the manual on this, and experiment.