[OpenSCAD] Digging into search( )

clothbot andrew at plumb.org
Mon Apr 20 08:26:02 EDT 2015

It's aliiiiive!

First attempt at search simplification (passes regressions) is here:


See the "Files Changed" report for how I've simplified the usage:


I updated the example023.scad to wrap the built-in search() in a
user-defined search_vector_one() function to take advantage of simple
[for(i=...)] list building:

function search_vector_one(vec,table,col=0) = [for(i=[0:len(vec)-1])


I used the same search_vector_one() function in text-search-test.scad to
make it "just work":


The two "search-tests-unicode.scad" and "search-tests.scad" have been
significantly modified to reflect the simplified search behaviour.



As outlined in the comment here:



  "search" "(" match_value  "," string_or_vector_or_table
          ("," index_col_num )?
  match_value : ( Value::NUMBER | Value::STRING );
  string_or_vector_or_table : ( Value::STRING | "[" Value ("," Value)* "]" | 
"[" ("[" Value ("," Value)* "]")+ "]" );
  index_col_num : int;


- A string 'match_value' searches for full-string matches.
  - It does *not* iterate over each character in the string and return a
list of matches per character any more.

- All matches are returned every time
  - no more 'num_returns_per_match' parameter.
  - use user-defined functions like the above search_vector_one() example to
massage search results to your liking.

- the no-matches condition returns 'undef' instead of an empty vector '[]'
  - conditional expressions based on no-search-results will work now.

- Assigning any vector to 'match_value' throws a WARNING and return 'undef'
  - I started trying to get smart and 'collapse vectors of length=1' for
backward compatibility but... no. Better to rip this bandaid off clean.
  - Perhaps a future enhancement could support vector-type match_value for
things like searching for points... That could be handy for process
polygon() and polyhedron() point sets.

Thoughts? Comments?

Speak now or fix it yourself.?. ;-)


View this message in context: http://forum.openscad.org/Digging-into-search-tp12421p12442.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

More information about the Discuss mailing list