<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Yeah, when I wrote search() the two primary use modes I focused on were basic character(s)-in-string and searching for matches in list-of-lists.<div class=""><br class=""></div><div class="">Have a look at my old example23.scad (see <a href="https://github.com/openscad/openscad/blob/master/examples/Old/example023.scad" class="">https://github.com/openscad/openscad/blob/master/examples/Old/example023.scad</a>) and how I structured MCAD/fonts.scad (see <a href="https://github.com/openscad/MCAD/blob/master/fonts.scad" class="">https://github.com/openscad/MCAD/blob/master/fonts.scad</a>)  to get some insight into how I wanted to (ab)use it.</div><div class=""><div class=""><br class=""></div><div class="">Andrew.</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 13, 2015, at 5:20 PM, runsun <<a href="mailto:runsun@gmail.com" class="">runsun@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Many thx, Andrew. Embarrassingly, I didn't even know there's a search(). Only knew about lookup.

With search(), the hash() function becomes ridiculously simple:

<code class=""><pre class="">function hash(h,k, notfound=undef)= 
(
    let( rtn= search([k],h) )
    len(rtn)>0? h[rtn[0]+1]: notfound    
);

opt = ["Height", 7, "Thickness", 5, "PinDiameter", 2];

echo( hash(opt,"Height") ); // 7
echo( hash(opt,"Thickness") ); //5
echo( hash(opt,"New") ); // undef ==> This also generates a warning.

I notice that there's a little "hiccup" (for me) when using search():

//Search a str in a string: 
search( "b","abcd" ) //==> [1]

//Search a str in a list: 
search( "b",["a","b","c"] ) //==> error 

// Search a str in a list:  NOTE: argument one has to be a list
search( ["b"],["a","b","c"] ) //==> [1]   

//Search a string in a list of str: 
search("b", [ ["a",10], ["b",11],["c",12] ] ) ) //==> [1]
</pre></code>

But, it's not a big issue. It seems that search() is a great tool and there are lots more to dig into.







        
        
        <div class="signature" style="margin-top:1em;color:#666666;font-size:11px;">
                                <div style="color:darkkhaki" class="">
<a href="http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1" target="_top" rel="nofollow" link="external" class="">$</a> <u class="">Runsun Pan, PhD</u> <br class="">

$ -- <b class="">OpenScad_DocTest</b>: doc and unit test ( <a style="color:darkkhaki" href="https://github.com/runsun/openscad_doctest" target="_top" rel="nofollow" link="external" class="">Github</a>, <a style="color:darkkhaki" href="https://www.thingiverse.com/thing:410831" target="_top" rel="nofollow" link="external" class="">Thingiverse</a> )<br class="">

$ -- <b class="">hash parameter model</b>: <a style="color:darkkhaki" href="http://forum.openscad.org/parameterized-models-td8303.html#a8306" target="_top" rel="nofollow" link="external" class="">here</a>, <a style="color:darkkhaki" href="http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12355.html" target="_top" rel="nofollow" link="external" class="">here</a><br class="">

$ -- <u class="">Linux Mint 17.1 Rebecca x64</u>  + <u class="">OpenSCAD 2015.03.15</u>/<u class="">2015.04.01.nightly</u><br class="">
<!--$ -- <u>Linux Mint 17 MATE 64bit</u>  + <u>OpenSCAD 2015.02.01.nightly</u><br/>-->
<!--$ -- <u>Linux Mint 17 MATE 64bit</u>  + <u>OpenSCAD 2014.10.02 64bit snapshot</u>-->
<!--$ -- <u>Linux Mint 17 MATE 64bit</u>  + <u>OpenSCAD 2014.05.31 snapshot</u><br/>
<span style="display:none;text-decoration:line-through">$ -- Linux Mint 17 MATE 64bit + Wine 1.6.2 + OpenSCAD for Windows 2014.07.22 snapshot</span>-->
</div></div>
                        
<br class=""><hr align="left" width="300" class="">
View this message in context: <a href="http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12358.html" class="">Re: Can I get some code review up in here?</a><br class="">
Sent from the <a href="http://forum.openscad.org/" class="">OpenSCAD mailing list archive</a> at <a href="http://Nabble.com" class="">Nabble.com</a>.<br class="">_______________________________________________<br class="">OpenSCAD mailing list<br class=""><a href="mailto:Discuss@lists.openscad.org" class="">Discuss@lists.openscad.org</a><br class="">http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>