1. Documentaion update request for "find"

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

new topic     » topic index » view message » categorize

2. Re: Documentaion update request for "find"

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Documentaion update request for "find"

alanjohnoxley said...

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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Documentaion update request for "find"

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Documentaion update request for "find"

alanjohnoxley said...

"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

SPringle said...

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.

alanjohnoxley said...

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().

new topic     » goto parent     » topic index » view message » categorize

6. Re: Documentaion update request for "find"

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.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Documentaion update request for "find"

alanjohnoxley said...

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Documentaion update request for "find"

OK Jim,
I'll read the manual on this, and experiment.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu