discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

search function is broken

AC
A. Craig West
Sun, Feb 13, 2022 10:11 PM

I just created an issue in git:
https://github.com/openscad/openscad/issues/4119
It looks like the search function is broken when searching lists of lists.
If it WAS working properly, is there a way to disable the warning? With it
there, it makes it pretty much impossible to do anything non-trivial using
the function with 'stop on first warning' set

-Craig

I just created an issue in git: https://github.com/openscad/openscad/issues/4119 It looks like the search function is broken when searching lists of lists. If it WAS working properly, is there a way to disable the warning? With it there, it makes it pretty much impossible to do anything non-trivial using the function with 'stop on first warning' set -Craig
AM
Adrian Mariano
Sun, Feb 13, 2022 10:24 PM

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".  Did you
read the manual?

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

As you invoke it in your example you're searching for "M" and "3".
You need to search for ["M3"] if you want to look for the string "M3"
instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com wrote:

I just created an issue in git: https://github.com/openscad/openscad/issues/4119
It looks like the search function is broken when searching lists of lists. If it WAS working properly, is there a way to disable the warning? With it there, it makes it pretty much impossible to do anything non-trivial using the function with 'stop on first warning' set

-Craig


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I mean, the search() function is arguably broken in that it is hard to imagine a worse designed function. But it does "work". Did you read the manual? https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search As you invoke it in your example you're searching for "M" and "3". You need to search for ["M3"] if you want to look for the string "M3" instead of the individual characters. On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> wrote: > > I just created an issue in git: https://github.com/openscad/openscad/issues/4119 > It looks like the search function is broken when searching lists of lists. If it WAS working properly, is there a way to disable the warning? With it there, it makes it pretty much impossible to do anything non-trivial using the function with 'stop on first warning' set > > -Craig > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
AC
A. Craig West
Sun, Feb 13, 2022 10:29 PM

I misunderstood the documentation when I read it the first time, the
behaviour IS correct. Not very intuitive, but correct...

On Sun, Feb 13, 2022 at 5:24 PM Adrian Mariano avm4@cornell.edu wrote:

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".  Did you
read the manual?

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

As you invoke it in your example you're searching for "M" and "3".
You need to search for ["M3"] if you want to look for the string "M3"
instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com
wrote:

I just created an issue in git:

It looks like the search function is broken when searching lists of

lists. If it WAS working properly, is there a way to disable the warning?
With it there, it makes it pretty much impossible to do anything
non-trivial using the function with 'stop on first warning' set

-Craig


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I misunderstood the documentation when I read it the first time, the behaviour IS correct. Not very intuitive, but correct... On Sun, Feb 13, 2022 at 5:24 PM Adrian Mariano <avm4@cornell.edu> wrote: > I mean, the search() function is arguably broken in that it is hard > to imagine a worse designed function. But it does "work". Did you > read the manual? > > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search > > As you invoke it in your example you're searching for "M" and "3". > You need to search for ["M3"] if you want to look for the string "M3" > instead of the individual characters. > > On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> > wrote: > > > > I just created an issue in git: > https://github.com/openscad/openscad/issues/4119 > > It looks like the search function is broken when searching lists of > lists. If it WAS working properly, is there a way to disable the warning? > With it there, it makes it pretty much impossible to do anything > non-trivial using the function with 'stop on first warning' set > > > > -Craig > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
M
MichaelAtOz
Sun, Feb 13, 2022 10:30 PM

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".

Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my
experiments.

But it is also very flexible.

Now if we can only get rid of the Warning when something is not found.
Often not finding something is just as valid as a match.

-----Original Message-----
From: Adrian Mariano [mailto:avm4@cornell.edu]
Sent: Mon, 14 Feb 2022 09:24
To: OpenSCAD general discussion
Subject: [OpenSCAD] Re: search function is broken

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".  Did you
read the manual?

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

As you invoke it in your example you're searching for "M" and "3".
You need to search for ["M3"] if you want to look for the string "M3"
instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com wrote:

I just created an issue in git: https://github.com/openscad/openscad/issues/4119
It looks like the search function is broken when searching lists of lists. If it WAS

working properly, is there a way to disable the warning? With it there, it makes it pretty
much impossible to do anything non-trivial using the function with 'stop on first warning'
set

-Craig


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
This email has been checked for viruses by AVG.
https://www.avg.com

> I mean, the search() function is arguably broken in that it is hard > to imagine a worse designed function. But it does "work". Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my experiments. But it is also very flexible. Now if we can only get rid of the Warning when something is not found. Often not finding something is just as valid as a match. > -----Original Message----- > From: Adrian Mariano [mailto:avm4@cornell.edu] > Sent: Mon, 14 Feb 2022 09:24 > To: OpenSCAD general discussion > Subject: [OpenSCAD] Re: search function is broken > > I mean, the search() function is arguably broken in that it is hard > to imagine a worse designed function. But it does "work". Did you > read the manual? > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search > > As you invoke it in your example you're searching for "M" and "3". > You need to search for ["M3"] if you want to look for the string "M3" > instead of the individual characters. > > On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> wrote: > > > > I just created an issue in git: https://github.com/openscad/openscad/issues/4119 > > It looks like the search function is broken when searching lists of lists. If it WAS > working properly, is there a way to disable the warning? With it there, it makes it pretty > much impossible to do anything non-trivial using the function with 'stop on first warning' > set > > > > -Craig > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org -- This email has been checked for viruses by AVG. https://www.avg.com
FH
Father Horton
Sun, Feb 13, 2022 10:35 PM

Has anyone looked at adding a regular expressions engine?

Has anyone looked at adding a regular expressions engine?
AC
A. Craig West
Sun, Feb 13, 2022 10:40 PM

On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz oz.at.michael@gmail.com wrote:

Now if we can only get rid of the Warning when something is not found.
Often not finding something is just as valid as a match.

The warning is inconsistent. In the version of the code that tgried to
search for the string directly, I got the warning, but if I search for a
list of one string, it does not give the warning.

On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz <oz.at.michael@gmail.com> wrote: >Now if we can only get rid of the Warning when something is not found. >Often not finding something is just as valid as a match. The warning is inconsistent. In the version of the code that tgried to search for the string directly, I got the warning, but if I search for a list of one string, it does not give the warning.
AM
Adrian Mariano
Sun, Feb 13, 2022 10:43 PM

Actually a lot of the wiki is from my experiments.  There is only a
warning when something is not found if you search for characters of a
string in a list of lists.  This is arguably a useless case anyway, so
it isn't much of a limitation.

As the wiki says, first about the search argument:

Can be a single string value. Search loops over the characters in the
string and searches for each one in the second argument. The second
argument must be a string or a list of lists (this second case is not
recommended). The search function does not search for substrings.

Why is the second case not recommended?  Below it says:

If match_value is a string and this parameter is a list of lists then
the characters of the string are tested against the appropriate index
entry in the list of lists. However, if any characters fail to find a
match a warning message is printed and that return value is excluded
from the output (if num_returns_per_match is 1). This means that the
length of the output is unpredictable.

There is a much more serious limitation.  Suppose you want to search
for 5 in a list:

echo(search([5], [5,7,[5,6]],0));

returns [[0,2]], which means it hits on the both 5 and [5,6].  So if
you actually just want to find matches to 5 you have to go back and
check all the hits and see which ones actually match.  We've had to
do stuff like this in BOSL2 to make things robust.  (What if a list
doesn't contain what you think it does?)

On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz oz.at.michael@gmail.com wrote:

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".

Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my
experiments.

But it is also very flexible.

Now if we can only get rid of the Warning when something is not found.
Often not finding something is just as valid as a match.

-----Original Message-----
From: Adrian Mariano [mailto:avm4@cornell.edu]
Sent: Mon, 14 Feb 2022 09:24
To: OpenSCAD general discussion
Subject: [OpenSCAD] Re: search function is broken

I  mean, the search() function is arguably broken in that it is hard
to imagine a worse designed function.  But it does "work".  Did you
read the manual?

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search

As you invoke it in your example you're searching for "M" and "3".
You need to search for ["M3"] if you want to look for the string "M3"
instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com wrote:

I just created an issue in git: https://github.com/openscad/openscad/issues/4119
It looks like the search function is broken when searching lists of lists. If it WAS
working properly, is there a way to disable the warning? With it there, it makes it pretty
much impossible to do anything non-trivial using the function with 'stop on first warning'
set

-Craig


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
This email has been checked for viruses by AVG.
https://www.avg.com


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Actually a lot of the wiki is from *my* experiments. There is only a warning when something is not found if you search for characters of a string in a list of lists. This is arguably a useless case anyway, so it isn't much of a limitation. As the wiki says, first about the search argument: Can be a single string value. Search loops over the characters in the string and searches for each one in the second argument. The second argument must be a string or a list of lists (this second case is not recommended). The search function does not search for substrings. Why is the second case not recommended? Below it says: If match_value is a string and this parameter is a list of lists then the characters of the string are tested against the appropriate index entry in the list of lists. However, if any characters fail to find a match a warning message is printed and that return value is excluded from the output (if num_returns_per_match is 1). This means that the length of the output is unpredictable. There is a much more serious limitation. Suppose you want to search for 5 in a list: echo(search([5], [5,7,[5,6]],0)); returns [[0,2]], which means it hits on the both 5 and [5,6]. So if you actually just want to find matches to 5 you have to go back and check all the hits and see which ones actually match. We've had to do stuff like this in BOSL2 to make things robust. (What if a list doesn't contain what you think it does?) On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz <oz.at.michael@gmail.com> wrote: > > > I mean, the search() function is arguably broken in that it is hard > > to imagine a worse designed function. But it does "work". > > Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my > experiments. > > But it is also very flexible. > > Now if we can only get rid of the Warning when something is not found. > Often not finding something is just as valid as a match. > > > -----Original Message----- > > From: Adrian Mariano [mailto:avm4@cornell.edu] > > Sent: Mon, 14 Feb 2022 09:24 > > To: OpenSCAD general discussion > > Subject: [OpenSCAD] Re: search function is broken > > > > I mean, the search() function is arguably broken in that it is hard > > to imagine a worse designed function. But it does "work". Did you > > read the manual? > > > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search > > > > As you invoke it in your example you're searching for "M" and "3". > > You need to search for ["M3"] if you want to look for the string "M3" > > instead of the individual characters. > > > > On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> wrote: > > > > > > I just created an issue in git: https://github.com/openscad/openscad/issues/4119 > > > It looks like the search function is broken when searching lists of lists. If it WAS > > working properly, is there a way to disable the warning? With it there, it makes it pretty > > much impossible to do anything non-trivial using the function with 'stop on first warning' > > set > > > > > > -Craig > > > _______________________________________________ > > > OpenSCAD mailing list > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > -- > This email has been checked for viruses by AVG. > https://www.avg.com > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
AM
Adrian Mariano
Sun, Feb 13, 2022 10:45 PM

Yes, it's been done in userspace here:  https://www.thingiverse.com/thing:526023

On Sun, Feb 13, 2022 at 5:36 PM Father Horton fatherhorton@gmail.com wrote:

Has anyone looked at adding a regular expressions engine?  _______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes, it's been done in userspace here: https://www.thingiverse.com/thing:526023 On Sun, Feb 13, 2022 at 5:36 PM Father Horton <fatherhorton@gmail.com> wrote: > > Has anyone looked at adding a regular expressions engine? _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
M
MichaelAtOz
Sun, Feb 13, 2022 11:08 PM

Actually a lot of the wiki is from my experiments.

Sorry, I hadn't looked in a while, at some stage it was my experiments to build on...probably  more
than 8 years ago.

I noticed the warning when someone asked about a very old Thingi
https://www.thingiverse.com/thing:415487  I did in another time, pre warnings.

It checks if text contains letters with a decent so it can offset write() texts position
appropriately.

function decentOther(text) =

                    (search(text,[ ["g"],["j"],["p"],["q"],["y"] ]) == [])

                    ? 0

                    : 1;

At the time the most straight forward test, now a warning for each letter in the text.

-----Original Message-----

From: Adrian Mariano [mailto:avm4@cornell.edu]

Sent: Mon, 14 Feb 2022 09:43

To: OpenSCAD general discussion

Subject: [OpenSCAD] Re: search function is broken

Actually a lot of the wiki is from my experiments.  There is only a

warning when something is not found if you search for characters of a

string in a list of lists.  This is arguably a useless case anyway, so

it isn't much of a limitation.

As the wiki says, first about the search argument:

Can be a single string value. Search loops over the characters in the

string and searches for each one in the second argument. The second

argument must be a string or a list of lists (this second case is not

recommended). The search function does not search for substrings.

Why is the second case not recommended?  Below it says:

If match_value is a string and this parameter is a list of lists then

the characters of the string are tested against the appropriate index

entry in the list of lists. However, if any characters fail to find a

match a warning message is printed and that return value is excluded

from the output (if num_returns_per_match is 1). This means that the

length of the output is unpredictable.

There is a much more serious limitation.  Suppose you want to search

for 5 in a list:

echo(search([5], [5,7,[5,6]],0));

returns [[0,2]], which means it hits on the both 5 and [5,6].  So if

you actually just want to find matches to 5 you have to go back and

check all the hits and see which ones actually match.  We've had to

do stuff like this in BOSL2 to make things robust.  (What if a list

doesn't contain what you think it does?)

On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz oz.at.michael@gmail.com wrote:

I  mean, the search() function is arguably broken in that it is hard

to imagine a worse designed function.  But it does "work".

Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my

experiments.

But it is also very flexible.

Now if we can only get rid of the Warning when something is not found.

Often not finding something is just as valid as a match.

-----Original Message-----

From: Adrian Mariano [mailto:avm4@cornell.edu]

Sent: Mon, 14 Feb 2022 09:24

To: OpenSCAD general discussion

Subject: [OpenSCAD] Re: search function is broken

I  mean, the search() function is arguably broken in that it is hard

to imagine a worse designed function.  But it does "work".  Did you

read the manual?

As you invoke it in your example you're searching for "M" and "3".

You need to search for ["M3"] if you want to look for the string "M3"

instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com wrote:

I just created an issue in git: https://github.com/openscad/openscad/issues/4119

It looks like the search function is broken when searching lists of lists. If it WAS

working properly, is there a way to disable the warning? With it there, it makes it

pretty

much impossible to do anything non-trivial using the function with 'stop on first

warning'

set

-Craig


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org

--

This email has been checked for viruses by AVG.


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org

--
This email has been checked for viruses by AVG.
https://www.avg.com

> Actually a lot of the wiki is from *my* experiments. Sorry, I hadn't looked in a while, at some stage it was my experiments to build on...probably more than 8 years ago. I noticed the warning when someone asked about a very old Thingi <https://www.thingiverse.com/thing:415487> I did in another time, pre warnings. It checks if text contains letters with a decent so it can offset write() texts position appropriately. function decentOther(text) = (search(text,[ ["g"],["j"],["p"],["q"],["y"] ]) == []) ? 0 : 1; At the time the most straight forward test, now a warning for each letter in the text. > -----Original Message----- > From: Adrian Mariano [mailto:avm4@cornell.edu] > Sent: Mon, 14 Feb 2022 09:43 > To: OpenSCAD general discussion > Subject: [OpenSCAD] Re: search function is broken > > Actually a lot of the wiki is from *my* experiments. There is only a > warning when something is not found if you search for characters of a > string in a list of lists. This is arguably a useless case anyway, so > it isn't much of a limitation. > > As the wiki says, first about the search argument: > > Can be a single string value. Search loops over the characters in the > string and searches for each one in the second argument. The second > argument must be a string or a list of lists (this second case is not > recommended). The search function does not search for substrings. > > Why is the second case not recommended? Below it says: > > If match_value is a string and this parameter is a list of lists then > the characters of the string are tested against the appropriate index > entry in the list of lists. However, if any characters fail to find a > match a warning message is printed and that return value is excluded > from the output (if num_returns_per_match is 1). This means that the > length of the output is unpredictable. > > There is a much more serious limitation. Suppose you want to search > for 5 in a list: > > echo(search([5], [5,7,[5,6]],0)); > > returns [[0,2]], which means it hits on the both 5 and [5,6]. So if > you actually just want to find matches to 5 you have to go back and > check all the hits and see which ones actually match. We've had to > do stuff like this in BOSL2 to make things robust. (What if a list > doesn't contain what you think it does?) > > On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz <oz.at.michael@gmail.com> wrote: > > > > > I mean, the search() function is arguably broken in that it is hard > > > to imagine a worse designed function. But it does "work". > > > > Totally agree, I had lots of problems understanding it, and a lot of the wiki is from my > > experiments. > > > > But it is also very flexible. > > > > Now if we can only get rid of the Warning when something is not found. > > Often not finding something is just as valid as a match. > > > > > -----Original Message----- > > > From: Adrian Mariano [mailto:avm4@cornell.edu] > > > Sent: Mon, 14 Feb 2022 09:24 > > > To: OpenSCAD general discussion > > > Subject: [OpenSCAD] Re: search function is broken > > > > > > I mean, the search() function is arguably broken in that it is hard > > > to imagine a worse designed function. But it does "work". Did you > > > read the manual? > > > > > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search > > > > > > As you invoke it in your example you're searching for "M" and "3". > > > You need to search for ["M3"] if you want to look for the string "M3" > > > instead of the individual characters. > > > > > > On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> wrote: > > > > > > > > I just created an issue in git: https://github.com/openscad/openscad/issues/4119 > > > > It looks like the search function is broken when searching lists of lists. If it WAS > > > working properly, is there a way to disable the warning? With it there, it makes it > pretty > > > much impossible to do anything non-trivial using the function with 'stop on first > warning' > > > set > > > > > > > > -Craig > > > > _______________________________________________ > > > > OpenSCAD mailing list > > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > > > OpenSCAD mailing list > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > > > -- > > This email has been checked for viruses by AVG. > > https://www.avg.com > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org -- This email has been checked for viruses by AVG. https://www.avg.com
AM
Adrian Mariano
Sun, Feb 13, 2022 11:14 PM

Yes, I was definitely building on the work of those who went before with
the wiki.  For your example you just need to rewrite the search as
search(text,"gjpqy").  I can't imagine why anybody thought issuing a
warning when you don't find something was a good idea.  But like I said,
it's a use situation that never needs to be used, so it doesn't create any
limits.  Just don't do that.

On Sun, Feb 13, 2022 at 6:08 PM MichaelAtOz oz.at.michael@gmail.com wrote:

Actually a lot of the wiki is from my experiments.

Sorry, I hadn't looked in a while, at some stage it was my experiments to
build on...probably  more than 8 years ago.

I noticed the warning when someone asked about a very old Thingi
https://www.thingiverse.com/thing:415487 I did in another time, pre
warnings.

It checks if text contains letters with a decent so it can offset write()
texts position appropriately.

function decentOther(text) =

                     (search(text,[ ["g"],["j"],["p"],["q"],["y"] ]) ==

[])

                     ? 0

                     : 1;

At the time the most straight forward test, now a warning for each letter
in the text.

-----Original Message-----

From: Adrian Mariano [mailto:avm4@cornell.edu]

Sent: Mon, 14 Feb 2022 09:43

To: OpenSCAD general discussion

Subject: [OpenSCAD] Re: search function is broken

Actually a lot of the wiki is from my experiments.  There is only a

warning when something is not found if you search for characters of a

string in a list of lists.  This is arguably a useless case anyway, so

it isn't much of a limitation.

As the wiki says, first about the search argument:

Can be a single string value. Search loops over the characters in the

string and searches for each one in the second argument. The second

argument must be a string or a list of lists (this second case is not

recommended). The search function does not search for substrings.

Why is the second case not recommended?  Below it says:

If match_value is a string and this parameter is a list of lists then

the characters of the string are tested against the appropriate index

entry in the list of lists. However, if any characters fail to find a

match a warning message is printed and that return value is excluded

from the output (if num_returns_per_match is 1). This means that the

length of the output is unpredictable.

There is a much more serious limitation.  Suppose you want to search

for 5 in a list:

echo(search([5], [5,7,[5,6]],0));

returns [[0,2]], which means it hits on the both 5 and [5,6].  So if

you actually just want to find matches to 5 you have to go back and

check all the hits and see which ones actually match.  We've had to

do stuff like this in BOSL2 to make things robust.  (What if a list

doesn't contain what you think it does?)

On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz oz.at.michael@gmail.com

wrote:

I  mean, the search() function is arguably broken in that it is hard

to imagine a worse designed function.  But it does "work".

Totally agree, I had lots of problems understanding it, and a lot of

the wiki is from my

experiments.

But it is also very flexible.

Now if we can only get rid of the Warning when something is not found.

Often not finding something is just as valid as a match.

-----Original Message-----

From: Adrian Mariano [mailto:avm4@cornell.edu]

Sent: Mon, 14 Feb 2022 09:24

To: OpenSCAD general discussion

Subject: [OpenSCAD] Re: search function is broken

I  mean, the search() function is arguably broken in that it is hard

to imagine a worse designed function.  But it does "work".  Did you

read the manual?

As you invoke it in your example you're searching for "M" and "3".

You need to search for ["M3"] if you want to look for the string "M3"

instead of the individual characters.

On Sun, Feb 13, 2022 at 5:12 PM A. Craig West acraigwest@gmail.com

wrote:

I just created an issue in git:

It looks like the search function is broken when searching lists

of lists. If it WAS

working properly, is there a way to disable the warning? With it

there, it makes it

pretty

much impossible to do anything non-trivial using the function with

'stop on first

warning'

set

-Craig


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org

--

This email has been checked for viruses by AVG.


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes, I was definitely building on the work of those who went before with the wiki. For your example you just need to rewrite the search as search(text,"gjpqy"). I can't imagine why anybody thought issuing a warning when you don't find something was a good idea. But like I said, it's a use situation that never needs to be used, so it doesn't create any limits. Just don't do that. On Sun, Feb 13, 2022 at 6:08 PM MichaelAtOz <oz.at.michael@gmail.com> wrote: > > Actually a lot of the wiki is from *my* experiments. > > > > Sorry, I hadn't looked in a while, at some stage it was my experiments to > build on...probably more than 8 years ago. > > > > I noticed the warning when someone asked about a very old Thingi > <https://www.thingiverse.com/thing:415487> I did in another time, pre > warnings. > > > > It checks if text contains letters with a decent so it can offset write() > texts position appropriately. > > > > function decentOther(text) = > > (search(text,[ ["g"],["j"],["p"],["q"],["y"] ]) == > []) > > ? 0 > > : 1; > > > > At the time the most straight forward test, now a warning for each letter > in the text. > > > > > > > -----Original Message----- > > > From: Adrian Mariano [mailto:avm4@cornell.edu] > > > Sent: Mon, 14 Feb 2022 09:43 > > > To: OpenSCAD general discussion > > > Subject: [OpenSCAD] Re: search function is broken > > > > > > Actually a lot of the wiki is from *my* experiments. There is only a > > > warning when something is not found if you search for characters of a > > > string in a list of lists. This is arguably a useless case anyway, so > > > it isn't much of a limitation. > > > > > > As the wiki says, first about the search argument: > > > > > > Can be a single string value. Search loops over the characters in the > > > string and searches for each one in the second argument. The second > > > argument must be a string or a list of lists (this second case is not > > > recommended). The search function does not search for substrings. > > > > > > Why is the second case not recommended? Below it says: > > > > > > If match_value is a string and this parameter is a list of lists then > > > the characters of the string are tested against the appropriate index > > > entry in the list of lists. However, if any characters fail to find a > > > match a warning message is printed and that return value is excluded > > > from the output (if num_returns_per_match is 1). This means that the > > > length of the output is unpredictable. > > > > > > There is a much more serious limitation. Suppose you want to search > > > for 5 in a list: > > > > > > echo(search([5], [5,7,[5,6]],0)); > > > > > > returns [[0,2]], which means it hits on the both 5 and [5,6]. So if > > > you actually just want to find matches to 5 you have to go back and > > > check all the hits and see which ones actually match. We've had to > > > do stuff like this in BOSL2 to make things robust. (What if a list > > > doesn't contain what you think it does?) > > > > > > On Sun, Feb 13, 2022 at 5:31 PM MichaelAtOz <oz.at.michael@gmail.com> > wrote: > > > > > > > > > I mean, the search() function is arguably broken in that it is hard > > > > > to imagine a worse designed function. But it does "work". > > > > > > > > Totally agree, I had lots of problems understanding it, and a lot of > the wiki is from my > > > > experiments. > > > > > > > > But it is also very flexible. > > > > > > > > Now if we can only get rid of the Warning when something is not found. > > > > Often not finding something is just as valid as a match. > > > > > > > > > -----Original Message----- > > > > > From: Adrian Mariano [mailto:avm4@cornell.edu] > > > > > Sent: Mon, 14 Feb 2022 09:24 > > > > > To: OpenSCAD general discussion > > > > > Subject: [OpenSCAD] Re: search function is broken > > > > > > > > > > I mean, the search() function is arguably broken in that it is hard > > > > > to imagine a worse designed function. But it does "work". Did you > > > > > read the manual? > > > > > > > > > > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Search > > > > > > > > > > As you invoke it in your example you're searching for "M" and "3". > > > > > You need to search for ["M3"] if you want to look for the string "M3" > > > > > instead of the individual characters. > > > > > > > > > > On Sun, Feb 13, 2022 at 5:12 PM A. Craig West <acraigwest@gmail.com> > wrote: > > > > > > > > > > > > I just created an issue in git: > https://github.com/openscad/openscad/issues/4119 > > > > > > It looks like the search function is broken when searching lists > of lists. If it WAS > > > > > working properly, is there a way to disable the warning? With it > there, it makes it > > > pretty > > > > > much impossible to do anything non-trivial using the function with > 'stop on first > > > warning' > > > > > set > > > > > > > > > > > > -Craig > > > > > > _______________________________________________ > > > > > > OpenSCAD mailing list > > > > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > > _______________________________________________ > > > > > OpenSCAD mailing list > > > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > > > > > > > > > -- > > > > This email has been checked for viruses by AVG. > > > > https://www.avg.com > > > > _______________________________________________ > > > > OpenSCAD mailing list > > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > > > OpenSCAD mailing list > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> Virus-free. > www.avg.com > <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> > <#m_4062202864113913561_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >