empty for loops issue a warning in RC3

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

empty for loops issue a warning in RC3

adrianv
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: empty for loops issue a warning in RC3

RevarBat
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 <[hidden email]> 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
> [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: empty for loops issue a warning in RC3

thehans
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 <[hidden email]> 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 <[hidden email]> 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
> [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
Reply | Threaded
Open this post in threaded view
|

Re: empty for loops issue a warning in RC3

adrianv
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/

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