[OpenSCAD] DEPRECATED: Using ranges of the form [begin:end] with begin value greater than the end value is deprecated.

adrianv avm4 at cornell.edu
Wed May 22 15:14:51 EDT 2019


The problem is not that they include the last value, though one can debate
that decision. The problem is that [0:-1] counts from the end instead of
giving you the empty list.  And the solution, without any changes to
OpenSCAD, is to simply write your code with a step size of 1 as

[0:1:len(list)-1]

which will do the right thing in all cases.  No special casing or tests are
needed.  Just always put in that step size of 1.  

But the problem I'm struggling with is that I'm running code that has
libraries so there are hundreds of lines of code, and I get this warning
that somewhere in my code I have the flipped range order.  How the heck am I
supposed to find it and fix it?  Is there a way to get the deprecation to be
an actual warning so that "stop on first warning" will stop and give me a
trace?  Because otherwise it can be quite the guessing game.  


nophead wrote
> The problem with OpenSCAD ranges is they include the last value, so you
> can
> never have a loop that doesn't do any iterations, you have to check for
> that first. When iterating over the indices of a list you need [0 :
> len(list) -1] but then if the list is empty you get [0 : -1] which I think
> warns and then iterates backwards. All other languages I know use half
> open
> ranges, so can have zero elements and don't need the -1.
> 
> Using the new C style loops is a work around for that.
> 
> On Wed, 22 May 2019 at 17:41, A. Craig West <

> acraigwest@

> > wrote:
> 
>> It occurs to me that I haven't checked this since I switched to more
>> recent builds. It was certainly the behavior in the 2015 version, but
>> that
>> is much less relevant now 😊.
>> I shall give this a try. Hopefully thingiverse will start using the new
>> version for their customiser, as that has been the only thing keeping me
>> back on that one...
>>
>> On Wed, 22 May 2019, 12:32 Torsten Paul, <

> Torsten.Paul@

> > wrote:
>>
>>> On 22.05.19 15:15, A. Craig West wrote:
>>> > len(v) == 0 ? [] :
>>> > [ for (o = v)...]
>>>
>>> This has nothing to do with ranges as far as I can see. Can
>>> you elaborate on why that is needed? If there's a bug then
>>> it can only be fixed if it's reported.
>>>
>>> v = [];
>>> echo([for (a = v) a]);
>>>
>>> Works fine and reports an empty list which is what I would
>>> expect. So in which case is that len() needed?
>>>
>>> ciao,
>>>   Torsten.
>>>
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> 

> Discuss at .openscad

>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>>
>> _______________________________________________
>> OpenSCAD mailing list
>> 

> Discuss at .openscad

>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
> 
> _______________________________________________
> OpenSCAD mailing list

> Discuss at .openscad

> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org





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



More information about the Discuss mailing list