[OpenSCAD] Digging into search( )

runsun runsun at gmail.com
Mon Apr 20 18:49:46 EDT 2015


@ Michael, I didn't explain too much in details about the context, I guess
that's why you (and Andrew) misunderstood. 

The reason that I have this argument,

     search( "def", [ "abc","def","def",1 ] ) 

will cause confusion is that, the whole discussion stems from a discussion
on other thread about hash parameter mapping. This includes the example you
gave using lookup. 

Then search() was mentioned. Search() was not designed for this type of
key-value mapping, but I tried to use it that way, by applying search() on a
flat list as above. Note that all examples on the doc about search() are
either against strings :

    search( ... "abcdef")

or against list of vectors:

    search( ... [["abc",1],["def",2] ...])

but not flat list.

So if search() is to be use as a key-value type mapping against a flat list
like I like it to be, it has to be able to find every other item to map,
that is, 

    search( "def", ["abc", "def", "def", 1] )

def has to map item 0, that is "abc", and skip item 1 (which is a value
associates to item 0), then item 2, that is "def". 

In this case, it should have returned [2]. Or, if return all, [1,2].

But, like I said, search() can't do that, and when set to return only one
item, it will return [1], but not [2], which is not what I want. So using
search() in a key-value mapping manner will fail. 

This can be solved if search() can match every other item (see my previous
post). 

But I understand that this is probably just my way of using it, so I leave
the decision to Andrew. It would probably make it too complicated, anyway. 

So this is not the problem of mistaking the base indexing. Guess I was just
too lazy to explain the entire context. :( :( 


MichaelAtOz wrote
> I think you missed the point @runsun.
> 
> "Very briefly, vector and string 'index' counting starts at 0, not 1. "
> 
> This explains why you had so much difficulty understanding it.
> 
> search("a",[ "d", "c", "b", "a"); // returns [3]
>                   0    1    2    3
>                                   __





-----

$  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: http://forum.openscad.org/Digging-into-search-tp12421p12452.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list