PiL3 icon indicating copy to clipboard operation
PiL3 copied to clipboard

7.2 wrong start

Open b10s opened this issue 7 years ago • 0 comments

https://github.com/xfbs/PiL3/blob/master/07Iterators/fromtostep.lua Hey, again : )

your code gives:

> for i in fromto(3,7,2) do print(i) end
4
6

but should be:

> for i in fromto(3,7,2) do print(i) end
3
5
7

my code:

function fromto(f,t,s)                                                              
    local iter; iter = function(s)                                                  
        s[1] = s[1] + s[3]                                                          
        if s[1]<=s[2] then                                                          
            return s[1]                                                             
        else                                                                        
            return nil                                                              
        end                                                                         
    end                                                                             
    return iter, {f-s,t,s}                                                          
end  

https://github.com/xfbs/PiL3/blob/master/07Iterators/fromtostep.lua#L26 min-1 should be min-step i guess

b10s avatar Jul 15 '17 23:07 b10s