[OpenSCAD] Can I get some code review up in here?

Andrew Plumb andrew at plumb.org
Mon Apr 13 19:09:06 EDT 2015


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.

Have a look at my old example23.scad (see https://github.com/openscad/openscad/blob/master/examples/Old/example023.scad <https://github.com/openscad/openscad/blob/master/examples/Old/example023.scad>) and how I structured MCAD/fonts.scad (see https://github.com/openscad/MCAD/blob/master/fonts.scad <https://github.com/openscad/MCAD/blob/master/fonts.scad>)  to get some insight into how I wanted to (ab)use it.

Andrew.


> On Apr 13, 2015, at 5:20 PM, runsun <runsun at gmail.com> wrote:
> 
> 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:
> 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]
> But, it's not a big issue. It seems that search() is a great tool and there are lots more to dig into.
> $ <http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> Runsun Pan, PhD 
> $ -- OpenScad_DocTest: doc and unit test ( Github <https://github.com/runsun/openscad_doctest>, Thingiverse <https://www.thingiverse.com/thing:410831> )
> $ -- hash parameter model: here <http://forum.openscad.org/parameterized-models-td8303.html#a8306>, here <http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12355.html>
> $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
> 
> View this message in context: Re: Can I get some code review up in here? <http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12358.html>
> Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> at Nabble.com.
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20150413/2ed720f3/attachment-0002.html>


More information about the Discuss mailing list