discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

empty for loops issue a warning in RC3

A
adrianv
Sat, Dec 26, 2020 12:19 AM

I would call this a bug.  Empty for loops are important for handling base
cases and degenerate cases elegantly.  This change reminds me of the worst
language I've ever used, IDL, where every base case needs special handling
because something always goes wrong.  (IDL had no empty list, so it would
return -1 instead of a list for "empty" for example.)

So examples of OpenSCAD code that didn't give warnings before but does now:

x = [for(i=[0:1:-1]) i];
x = [for(i=[0:-1:1]) i];

These constructions are not wrong and should not produce warnings.

--
Sent from: http://forum.openscad.org/

I would call this a bug. Empty for loops are important for handling base cases and degenerate cases elegantly. This change reminds me of the worst language I've ever used, IDL, where every base case needs special handling because something always goes wrong. (IDL had no empty list, so it would return -1 instead of a list for "empty" for example.) So examples of OpenSCAD code that didn't give warnings before but does now: x = [for(i=[0:1:-1]) i]; x = [for(i=[0:-1:1]) i]; These constructions are not wrong and should not produce warnings. -- Sent from: http://forum.openscad.org/
RD
Revar Desmera
Sat, Dec 26, 2020 1:02 AM

The idiom for (i = [0:1:len(list)-1]) is used all the time.  For an empty list, that translates to for (i=[0:1:-1]) which doesn’t run.  And that’s exactly how it is supposed to work.  Making it spit out a warning makes “stop on first warning” practically useless for a whole lot of my code.  Hell, the entire reason I started putting in the :1: in the middle of ranges was so it would NOT throw deprecation warnings and (iterate backwards).

This is DEFINITELY a bug.

  • Revar

On Dec 25, 2020, at 4:19 PM, adrianv avm4@cornell.edu wrote:

I would call this a bug.  Empty for loops are important for handling base
cases and degenerate cases elegantly.  This change reminds me of the worst
language I've ever used, IDL, where every base case needs special handling
because something always goes wrong.  (IDL had no empty list, so it would
return -1 instead of a list for "empty" for example.)

So examples of OpenSCAD code that didn't give warnings before but does now:

x = [for(i=[0:1:-1]) i];
x = [for(i=[0:-1:1]) i];

These constructions are not wrong and should not produce warnings.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

The idiom `for (i = [0:1:len(list)-1])` is used all the time. For an empty list, that translates to `for (i=[0:1:-1])` which doesn’t run. And that’s exactly how it is supposed to work. Making it spit out a warning makes “stop on first warning” practically useless for a whole lot of my code. Hell, the entire reason I started putting in the :1: in the middle of ranges was so it would NOT throw deprecation warnings and (iterate backwards). This is DEFINITELY a bug. - Revar > On Dec 25, 2020, at 4:19 PM, adrianv <avm4@cornell.edu> wrote: > > I would call this a bug. Empty for loops are important for handling base > cases and degenerate cases elegantly. This change reminds me of the worst > language I've ever used, IDL, where every base case needs special handling > because something always goes wrong. (IDL had no empty list, so it would > return -1 instead of a list for "empty" for example.) > > So examples of OpenSCAD code that didn't give warnings before but does now: > > x = [for(i=[0:1:-1]) i]; > x = [for(i=[0:-1:1]) i]; > > These constructions are not wrong and should not produce warnings. > > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
HL
Hans L
Sat, Dec 26, 2020 9:50 AM

I'm fairly certain that warning only shows if the range is composed
entirely of literal values and no other expressions or variables.
In that case where the user typed all literal values, I think
it's reasonable to assume it was done in error.

So, the following does NOT actually generate any warnings if you test it:
a = [];
b = -1;
x = [for(i=[0:1:len(a)-1]) i];
y = [for(i=[0:b:1]) i];

On Fri, Dec 25, 2020 at 7:03 PM Revar Desmera revarbat@gmail.com wrote:

The idiom for (i = [0:1:len(list)-1]) is used all the time.  For an
empty list, that translates to for (i=[0:1:-1]) which doesn’t run.  And
that’s exactly how it is supposed to work.  Making it spit out a warning
makes “stop on first warning” practically useless for a whole lot of my
code.  Hell, the entire reason I started putting in the :1: in the middle
of ranges was so it would NOT throw deprecation warnings and (iterate
backwards).

This is DEFINITELY a bug.

  • Revar

On Dec 25, 2020, at 4:19 PM, adrianv avm4@cornell.edu wrote:

I would call this a bug.  Empty for loops are important for handling base
cases and degenerate cases elegantly.  This change reminds me of the

worst

language I've ever used, IDL, where every base case needs special

handling

because something always goes wrong.  (IDL had no empty list, so it would
return -1 instead of a list for "empty" for example.)

So examples of OpenSCAD code that didn't give warnings before but does

now:

x = [for(i=[0:1:-1]) i];
x = [for(i=[0:-1:1]) i];

These constructions are not wrong and should not produce warnings.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I'm fairly certain that warning only shows if the range is composed entirely of literal values and no other expressions or variables. In that case where the user typed all literal values, I think it's reasonable to assume it was done in error. So, the following does NOT actually generate any warnings if you test it: a = []; b = -1; x = [for(i=[0:1:len(a)-1]) i]; y = [for(i=[0:b:1]) i]; On Fri, Dec 25, 2020 at 7:03 PM Revar Desmera <revarbat@gmail.com> wrote: > The idiom `for (i = [0:1:len(list)-1])` is used all the time. For an > empty list, that translates to `for (i=[0:1:-1])` which doesn’t run. And > that’s exactly how it is supposed to work. Making it spit out a warning > makes “stop on first warning” practically useless for a whole lot of my > code. Hell, the entire reason I started putting in the :1: in the middle > of ranges was so it would NOT throw deprecation warnings and (iterate > backwards). > > This is DEFINITELY a bug. > > - Revar > > > > On Dec 25, 2020, at 4:19 PM, adrianv <avm4@cornell.edu> wrote: > > > > I would call this a bug. Empty for loops are important for handling base > > cases and degenerate cases elegantly. This change reminds me of the > worst > > language I've ever used, IDL, where every base case needs special > handling > > because something always goes wrong. (IDL had no empty list, so it would > > return -1 instead of a list for "empty" for example.) > > > > So examples of OpenSCAD code that didn't give warnings before but does > now: > > > > x = [for(i=[0:1:-1]) i]; > > x = [for(i=[0:-1:1]) i]; > > > > These constructions are not wrong and should not produce warnings. > > > > > > > > > > > > > > -- > > Sent from: http://forum.openscad.org/ > > > > _______________________________________________ > > 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 >
A
adrianv
Sat, Dec 26, 2020 12:55 PM

You must be right about this.  I've been trying to understand why I am not
getting the warning in our regression tests, which I was pretty sure hit the
zero length case, and this answers that question.

thehans wrote

I'm fairly certain that warning only shows if the range is composed
entirely of literal values and no other expressions or variables.
In that case where the user typed all literal values, I think
it's reasonable to assume it was done in error.

So, the following does NOT actually generate any warnings if you test it:
a = [];
b = -1;
x = [for(i=[0:1:len(a)-1]) i];
y = [for(i=[0:b:1]) i];

On Fri, Dec 25, 2020 at 7:03 PM Revar Desmera <

revarbat@

> wrote:

The idiom for (i = [0:1:len(list)-1]) is used all the time.  For an
empty list, that translates to for (i=[0:1:-1]) which doesn’t run.  And
that’s exactly how it is supposed to work.  Making it spit out a warning
makes “stop on first warning” practically useless for a whole lot of my
code.  Hell, the entire reason I started putting in the :1: in the middle
of ranges was so it would NOT throw deprecation warnings and (iterate
backwards).

This is DEFINITELY a bug.

  • Revar

On Dec 25, 2020, at 4:19 PM, adrianv <

avm4@

> wrote:

I would call this a bug.  Empty for loops are important for handling

base

cases and degenerate cases elegantly.  This change reminds me of the

worst

language I've ever used, IDL, where every base case needs special

handling

because something always goes wrong.  (IDL had no empty list, so it

would

return -1 instead of a list for "empty" for example.)

So examples of OpenSCAD code that didn't give warnings before but does

now:

x = [for(i=[0:1:-1]) i];
x = [for(i=[0:-1:1]) i];

These constructions are not wrong and should not produce warnings.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list

Discuss@.openscad

Discuss@.openscad

Discuss@.openscad

You must be right about this. I've been trying to understand why I am not getting the warning in our regression tests, which I was pretty sure hit the zero length case, and this answers that question. thehans wrote > I'm fairly certain that warning only shows if the range is composed > entirely of literal values and no other expressions or variables. > In that case where the user typed all literal values, I think > it's reasonable to assume it was done in error. > > So, the following does NOT actually generate any warnings if you test it: > a = []; > b = -1; > x = [for(i=[0:1:len(a)-1]) i]; > y = [for(i=[0:b:1]) i]; > > > On Fri, Dec 25, 2020 at 7:03 PM Revar Desmera &lt; > revarbat@ > &gt; wrote: > >> The idiom `for (i = [0:1:len(list)-1])` is used all the time. For an >> empty list, that translates to `for (i=[0:1:-1])` which doesn’t run. And >> that’s exactly how it is supposed to work. Making it spit out a warning >> makes “stop on first warning” practically useless for a whole lot of my >> code. Hell, the entire reason I started putting in the :1: in the middle >> of ranges was so it would NOT throw deprecation warnings and (iterate >> backwards). >> >> This is DEFINITELY a bug. >> >> - Revar >> >> >> > On Dec 25, 2020, at 4:19 PM, adrianv &lt; > avm4@ > &gt; wrote: >> > >> > I would call this a bug. Empty for loops are important for handling >> base >> > cases and degenerate cases elegantly. This change reminds me of the >> worst >> > language I've ever used, IDL, where every base case needs special >> handling >> > because something always goes wrong. (IDL had no empty list, so it >> would >> > return -1 instead of a list for "empty" for example.) >> > >> > So examples of OpenSCAD code that didn't give warnings before but does >> now: >> > >> > x = [for(i=[0:1:-1]) i]; >> > x = [for(i=[0:-1:1]) i]; >> > >> > These constructions are not wrong and should not produce warnings. >> > >> > >> > >> > >> > >> > >> > -- >> > Sent from: http://forum.openscad.org/ >> > >> > _______________________________________________ >> > OpenSCAD mailing list >> > > Discuss@.openscad >> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> _______________________________________________ >> OpenSCAD mailing list >> > Discuss@.openscad >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Sent from: http://forum.openscad.org/