# [OpenSCAD] Digging into search( )

Sun Apr 19 16:30:54 EDT 2015

Yes, search is way too complicated for me to use as well. I just roll my
own with recursion if I need to search.

On 19 April 2015 at 20:37, runsun <runsun at gmail.com> 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.
>
> 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" ?
>
>    (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.
>
>    (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*.
>
> 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?? "
>
> 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.
>
>
>
> -----
>
> \$  Runsun Pan, PhD
>
> \$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse  )
>
> \$ -- hash parameter model: here , here
>
> \$ -- Linux Mint 17.1 Rebecca x64  + OpenSCAD 2015.03.15/2015.04.01.nightly
>
>
>
>
> --
> View this message in context: