On Thursday, July 3, 2014 10:15:31 AM UTC-5, Stefan Karpinski wrote:
>
> Oh yikes. That's not good at all. Python has the good behavior too.
>

This causes many "zero-length" problems in R because a

  for (i in 1:length(v)) {
   ...
 } 

>
loop is executed twice for a zero-length array, usually resulting in an 
indexing error.  It may indeed be part of the R FAQ that you should write 
the loop in R as

  for (i in seq(along = v)) {
   ...
 } 

>
to get the correct edge-case behavior.

This alone is enough to discourage such an interpretation of 1:0



> On Jul 3, 2014, at 10:22 AM, John Myles White <johnmyl...@gmail.com 
> <javascript:>> wrote:
>
> Sadly, R does not. 1:0 expands to c(1, 0). This is something that has 
> burned a lot of people in my experience. I imagine this is inherited from S.
>
>  — John
>
> On Jul 3, 2014, at 2:05 AM, Tobias Knopp <tobias...@googlemail.com 
> <javascript:>> wrote:
>
> Just as a side note (I entirely agree with Stefan), Matlab behaves the 
> same as Julia:
>
> >> 3:1
>
> ans =
>
>    Empty matrix: 1-by-0
>
>
> Am Donnerstag, 3. Juli 2014 03:38:32 UTC+2 schrieb Stefan Karpinski:
>>
>> It changes the meaning of a:b in a capricious way based on their values, 
>> which, while often appealing for the immediate situation – and thus rampant 
>> in dynamic languages – is almost always terrible for writing predictable, 
>> reliable code. 
>>
>>
>> On Wed, Jul 2, 2014 at 1:07 PM, Jay Kickliter <jay.ki...@gmail.com> 
>> wrote:
>>
>>> I assume that when I wake up at 5 AM to finish some DSP code. Really, it 
>>> was just a stupid mistake. From a non-programmer's perspective (me), it 
>>> seemed like it should have work. If you think that would be dangerous, I'll 
>>> take your word for it.
>>>
>>>
>>> On Wednesday, July 2, 2014 8:26:10 AM UTC-6, Stefan Karpinski wrote:
>>>
>>>> Why would one assume that the default step size is -1 when the start is 
>>>> bigger than the stop? The documentation for ranges clearly says that the 
>>>> default step size is 1 unconditionally, not that it is sign(stop-start). 
>>>> That would, by the way, be a very dangerous behavior. Perhaps a sidebar on 
>>>> the colon syntax is warranted in the manual control flow section on for 
>>>> loops, including examples of empty ranges and ranges that count downwards.
>>>>
>>>>
>>>> On Wed, Jul 2, 2014 at 9:53 AM, Jay Kickliter <jay.ki...@gmail.com> 
>>>> wrote:
>>>>
>>>>> I just realized that it works if I rewrite the range as 10:-1:1. It 
>>>>> seems to me that either big:small should work with a default step size of 
>>>>> -1, or the documentation needs a note. 
>>>>>
>>>>>
>>>>> On Wednesday, July 2, 2014 7:32:10 AM UTC-6, Jay Kickliter wrote:
>>>>>>
>>>>>> Are they meant to work? I could only find one meaning of them not 
>>>>>> working (issue 5778 <https://github.com/JuliaLang/julia/issues/5778>
>>>>>> ).
>>>>>>
>>>>>> Here's an example:
>>>>>>
>>>>>> julia> for i = 1:10
>>>>>>
>>>>>>            println(i)
>>>>>>
>>>>>>        end
>>>>>>
>>>>>> 1
>>>>>>
>>>>>> 2
>>>>>>
>>>>>> 3
>>>>>>
>>>>>> 4
>>>>>>
>>>>>> 5
>>>>>>
>>>>>> 6
>>>>>>
>>>>>> 7
>>>>>>
>>>>>> 8
>>>>>>
>>>>>> 9
>>>>>>
>>>>>> 10
>>>>>>
>>>>>>
>>>>>> julia> for i = 10:1
>>>>>>
>>>>>>            println(i)
>>>>>>
>>>>>>        end
>>>>>>
>>>>>>
>>>>>> julia> 
>>>>>>
>>>>>
>>>>
>>
>

Reply via email to