"lookup" with strings? a bug?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

"lookup" with strings? a bug?

tobject
Is lookup function searches for keys which are strings? say
<b> lookup("foo",myArray)? </b>

I get  undef back. Is this a bug?
what's the good Strings functions library for OpenScad?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: "lookup" with strings? a bug?

JordanBrown
On 5/29/2019 9:33 AM, Serge wrote:
Is lookup function searches for keys which are strings? say
<b> lookup("foo",myArray)? </b>

I get  undef back. Is this a bug?
what's the good Strings functions library for OpenScad?



lookup( ) doesn't explicitly say so, but since it interpolates it can't work on anything but numbers.

You want search( ).

Notes:
  • If you're searching for a string, the first argument needs to be an array containing as its only element that string.
  • For the default num_returns_to_match of 1, the not-found results are a little peculiar.  Found yields an array that contains as its only element the index of the entry; not-found yields an array that contains as its only element an empty array.
table=[ [ "bar", 0 ], [ "foo", 1 ], [ "foo", 1 ], [ "baz", 2 ] ];
echo(search(["baz"], table));
echo(search(["foo"], table));
echo(search(["junk"], table));

ECHO: [3]
ECHO: [1]
ECHO: [[]]


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: "lookup" with strings? a bug?

nophead
In reply to this post by tobject
Lookup is for numerical interpolation. You need search for strings,  https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

On Wed, 29 May 2019 at 17:34, Serge <[hidden email]> wrote:
Is lookup function searches for keys which are strings? say
<b> lookup("foo",myArray)? </b>

I get  undef back. Is this a bug?
what's the good Strings functions library for OpenScad?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: "lookup" with strings? a bug?

tobject
wait whaaaat?? I'm using search("top", … searching for "top" why it
returns me "type"? who wrote this rap?

On 5/29/19, nop head <[hidden email]> wrote:

> Lookup is for numerical interpolation. You need search for strings,
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search
>
> On Wed, 29 May 2019 at 17:34, Serge <[hidden email]> wrote:
>
>> Is lookup function searches for keys which are strings? say
>> <b> lookup("foo",myArray)? </b>
>>
>> I get  undef back. Is this a bug?
>> what's the good Strings functions library for OpenScad?
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: "lookup" with strings? a bug?

JordanBrown
On 5/29/2019 1:39 PM, Serge wrote:
wait whaaaat?? I'm using search("top", … searching for "top" why it
returns me "type"? who wrote this rap?

See the documentation and my note about how if you're searching for a string you need to make it be an array containing only that string.  When you just say "top" it's interpreted as "search for t, o, or p".

On 5/29/19, nop head [hidden email] wrote:
Lookup is for numerical interpolation. You need search for strings,
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

On Wed, 29 May 2019 at 17:34, Serge [hidden email] wrote:

Is lookup function searches for keys which are strings? say
<b> lookup("foo",myArray)? </b>

I get  undef back. Is this a bug?
what's the good Strings functions library for OpenScad?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


      
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org