discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

"lookup" with strings? a bug?

S
Serge
Wed, May 29, 2019 4:33 PM

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?

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?
JB
Jordan Brown
Wed, May 29, 2019 5:02 PM

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: [[]]

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: [[]]
NH
nop head
Wed, May 29, 2019 5:10 PM

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 moneyforidea@gmail.com 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <moneyforidea@gmail.com> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
S
Serge
Wed, May 29, 2019 8:39 PM

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 nop.head@gmail.com 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 moneyforidea@gmail.com 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <nop.head@gmail.com> 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 <moneyforidea@gmail.com> 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 >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >
JB
Jordan Brown
Wed, May 29, 2019 8:43 PM

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 nop.head@gmail.com 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 moneyforidea@gmail.com 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <nop.head@gmail.com> 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 <moneyforidea@gmail.com> 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 >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org