[OpenSCAD] Digging into search( )

MichaelAtOz oz.at.michael at gmail.com
Mon Apr 20 02:44:21 EDT 2015


runsun wrote
> Hi Michael, thx for your quick reply. It reveals to me that, even after I
> spent a lot of effort doing relatively extensive tests trying to
> understand how to use search(), I still miss something:
>    
>    (1) search( "abc","abcdabcd" )= [0, 1, 2] 
>    (2) search( ["a","b","c"],"abcdabcd" ) = [[], [], []]
> 
>    The 1st will match individual "a","b","c" to ANY CHARS in "abcdabcd"
>    but the 2nd will match the entire "abcdabcd". 
> 
> That is, 
*
> given a whole string will match partial string, but given a list of
> partial strings will match the whole string
*
> . This already complicated enough. 

(2) is Wiki: Note: If match_value is a vector of strings, search will look
for exact string matches.

> I am pretty sure that it already pass the boundary of my limited brain
> power. But that's not where the complication stops. 
> 
>    (3) search( ["a","bc","abcdabcd"],"abcdabcd" ) = want: [0] got: [[],
> [], []]
> 
> Didn't we say " If match_value is a vector of strings, search will look
> for exact string matches" ???
> 
> Where is the exact string match of the 3rd item, "abcdabcd" ?

Why do you expect [0]?
The "abcdabcd" not found part is unexpected. (bug or not designed for that)

>    (4) And another one:
> 
>       data9= [ ["cat", 1], ["b", 2], ["c", 3], ["dog", 4] 
>                 , ["a", 5], ["b", 6], ["c", 7], ["d", 8] 
>                 , ["e", 9], ["apple", 10], ["a", 11] ] 
> 
>       search( "act", data9, 0 ) 
>       |   want:
>       |   [[0, 4, 9, 10], [0, 2, 6], [0]]
>       |   got:
>       |   [[4, 9, 10], [0, 2, 6], []]
>     
> 
> As we mentioned, "act" is treated as vector of chars, and iterate over. It 
> means, "a" and "t"
> should have found a match in ["cat",1], but they don't.  

wiki:

match_value:
Can be a single value or vector of values.
Strings are treated as vectors-of-characters to iterate over; the search
function does not search for substrings.

So "a" & "t" do not match "cat", but "c" does. Not saying it's sensible.
Change "cat" to "tac" and the "t" matches.


> 
> 
>    (5) Another example:
> 
>    search( "ab",[["ab",1],["bc",2],["cd",3]], 0 )
>    |  want:
>    |  [[0], [0, 1]]
>    |  got:
>    |  [[0], [1]]
>    search( "bc",[["ab",1],["bc",2],["cd",3]], 0 )
>    |  want:
>    |  [[0, 1], [1, 2]]
>    |  got:
>    |  [[1], [2]]
>  
> It seems to me that, other than the already-complicated rule: "
*
> given a whole string will match partial string, but given a list of
> partial strings will match the whole string
*
> ", in come cases it matches an item of a list of strings to the 
*
> BEGINNING of a whole string
*
> .  

Seems the match is as you say, the beginning. Possibly an implementation
error when the match test was written.

> Up to this point, I am too tired trying to figure out yet another rule. 
> 
> You mentioned : " I suspect you may be reacting to the change to remove
> the Warnings?? "

That was in regard to you saying it wasn't ready for release. So I presumed
you saw the change and assumed search() was not released yet.

> Well, in fact, I haven't even started covering it yet. In the 2nd
> argument, 
/
> string_or_vectors
/
> , I only covered string and "list of lists", [ ["abc",1], ["def",2]...]. I
> haven't even covered my real concern : a flat list: [ "abc",1, "def",2...
> ], where my original "request of suppressing warning" lies on. 
> 
> Besides, I am using a nightly version in which the warning that bothered
> me in the first place has already been fixed.

search() worked for what I wanted it too do. I wrote that bit at the bottom
of the wiki "Getting the right results" to figure it out myself, some time
ago.



-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/Digging-into-search-tp12421p12439.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list