Numeric for loop with rationals

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Numeric for loop with rationals

Soni "They/Them" L.
I can't get `for x=r(1, 10), r(10, 10), r(1, 10) do print(x) end` to work.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

dyngeccetor8
On 01/29/2018 04:52 AM, Soni "They/Them" L. wrote:
> I can't get `for x=r(1, 10), r(10, 10), r(1, 10) do print(x) end` to work.
Me too.

-- Martin


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-29 09:00 PM, dyngeccetor8 wrote:
> On 01/29/2018 04:52 AM, Soni "They/Them" L. wrote:
>> I can't get `for x=r(1, 10), r(10, 10), r(1, 10) do print(x) end` to work.
> Me too.
>
> -- Martin
>
>

It errors that they aren't numbers. Ofc they aren't Lua numbers, they're
custom numbers.

It saddens me that Lua doesn't support custom numbers as well as other
languages (namely Python). :(

(We also don't have a __key mechanism to gracefully degrade objects into
interned table keys, so indexing with rationals is also painful... No,
you still don't need to expose the "hash" or "BTree" implementation
details to the user.)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

dyngeccetor8
On 01/30/2018 02:16 AM, Soni "They/Them" L. wrote:

>
> On 2018-01-29 09:00 PM, dyngeccetor8 wrote:
>> On 01/29/2018 04:52 AM, Soni "They/Them" L. wrote:
>>> I can't get `for x=r(1, 10), r(10, 10), r(1, 10) do print(x) end` to work.
>> Me too.
>
> It errors that they aren't numbers. Ofc they aren't Lua numbers, they're custom
> numbers.
>
> It saddens me that Lua doesn't support custom numbers as well as other languages
> (namely Python). :(
Because it's numeric "for".

There is generic "for" for iterating other things.

-- Martin

communicating.png (35K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-29 09:57 PM, dyngeccetor8 wrote:

> On 01/30/2018 02:16 AM, Soni "They/Them" L. wrote:
>> On 2018-01-29 09:00 PM, dyngeccetor8 wrote:
>>> On 01/29/2018 04:52 AM, Soni "They/Them" L. wrote:
>>>> I can't get `for x=r(1, 10), r(10, 10), r(1, 10) do print(x) end` to work.
>>> Me too.
>> It errors that they aren't numbers. Ofc they aren't Lua numbers, they're custom
>> numbers.
>>
>> It saddens me that Lua doesn't support custom numbers as well as other languages
>> (namely Python). :(
> Because it's numeric "for".
>
> There is generic "for" for iterating other things.
>
> -- Martin

Please don't post xkcds without (at the least) a link to the source.
It's a violation of the xkcd license https://xkcd.com/license.html

Also, rationals are still numbers. They're just not "Lua numbers"
(objects with type(x) == "number"). Any language with operator
overloading (e.g. C++) lets me have numeric for with rationals. Except
Lua. (Python doesn't have numeric for at all so it doesn't count.)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

nobody
On 2018-01-30 01:11, Soni "They/Them" L. wrote:
> (Python doesn't have numeric for at all so it doesn't count.)

So you're saying the numeric for is too much of a special case and
should be removed?

-- nobody

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Coda Highland
On Mon, Jan 29, 2018 at 6:21 PM, nobody <[hidden email]> wrote:

> On 2018-01-30 01:11, Soni "They/Them" L. wrote:
>>
>> (Python doesn't have numeric for at all so it doesn't count.)
>
>
> So you're saying the numeric for is too much of a special case and should be
> removed?
>
> -- nobody
>

I think it's more of a "could be" rather than a "should be".

Also, there's a delicious pun in there.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Vadi

What is the point of this email to the thousands of people exactly?

Let's keep the list productive please.


On Tue, 30 Jan 2018, 3:44 am Coda Highland, <[hidden email]> wrote:
On Mon, Jan 29, 2018 at 6:21 PM, nobody <[hidden email]> wrote:
> On 2018-01-30 01:11, Soni "They/Them" L. wrote:
>>
>> (Python doesn't have numeric for at all so it doesn't count.)
>
>
> So you're saying the numeric for is too much of a special case and should be
> removed?
>
> -- nobody
>

I think it's more of a "could be" rather than a "should be".

Also, there's a delicious pun in there.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Dirk Laurie-2
2018-01-30 7:40 GMT+02:00 Vadim Peretokin <[hidden email]>:
> What is the point of this email to the thousands of people exactly?
>
> Let's keep the list productive please.

For the sake of those whose English isrecreational:
Adam means that the sentence
   (Python doesn't have numeric for at all so it doesn't count.)
can be read in two ways.

Those like me who do British crosswords for fun would have
enjoyed Adam's post. I'm pretty sure Soni intended the pun,
but I missed it on first reading.

> On Tue, 30 Jan 2018, 3:44 am Coda Highland, <[hidden email]> wrote:
>> > On 2018-01-30 01:11, Soni "They/Them" L. wrote:
>> >> (Python doesn't have numeric for at all so it doesn't count.)
>> Also, there's a delicious pun in there.

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Tim Hill


> On Jan 29, 2018, at 9:49 PM, Dirk Laurie <[hidden email]> wrote:

> Those like me who do British crosswords for fun would have
> enjoyed Adam's post. I'm pretty sure Soni intended the pun,
> but I missed it on first reading.


Off topic…

(Real clue from some years back in Times Crossword…)

Clue: “H I J K L M N O” (5 letters)

—Tim


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Francisco Olarte
In reply to this post by Soni "They/Them" L.
On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]> wrote:
...
> Also, rationals are still numbers. They're just not "Lua numbers" (objects
> with type(x) == "number"). Any language with operator overloading (e.g. C++)
> lets me have numeric for with rationals. Except Lua. (Python doesn't have
> numeric for at all so it doesn't count.)

C++ does not have numeric for, so it doesn't count either.

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-30 06:58 AM, Francisco Olarte wrote:

> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]> wrote:
> ...
>> Also, rationals are still numbers. They're just not "Lua numbers" (objects
>> with type(x) == "number"). Any language with operator overloading (e.g. C++)
>> lets me have numeric for with rationals. Except Lua. (Python doesn't have
>> numeric for at all so it doesn't count.)
> C++ does not have numeric for, so it doesn't count either.
>
> Francisco Olarte.
>

for (int i = 0; i < 100; i++) { printf("%d\n", i); }

Looks like it does, it's just more flexible than Lua's.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Dirk Laurie-2
2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:

>
>
> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>>
>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
>> wrote:
>> ...
>>>
>>> Also, rationals are still numbers. They're just not "Lua numbers"
>>> (objects
>>> with type(x) == "number"). Any language with operator overloading (e.g.
>>> C++)
>>> lets me have numeric for with rationals. Except Lua. (Python doesn't have
>>> numeric for at all so it doesn't count.)
>>
>> C++ does not have numeric for, so it doesn't count either.
>>
>> Francisco Olarte.
>>
>
> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>
> Looks like it does, it's just more flexible than Lua's.

No 'for' is more flexible than Lua's.

for a,b,c,as_many_as_you_like in myiter(anything) do
end

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-30 10:51 AM, Dirk Laurie wrote:

> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>
>> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
>>> wrote:
>>> ...
>>>> Also, rationals are still numbers. They're just not "Lua numbers"
>>>> (objects
>>>> with type(x) == "number"). Any language with operator overloading (e.g.
>>>> C++)
>>>> lets me have numeric for with rationals. Except Lua. (Python doesn't have
>>>> numeric for at all so it doesn't count.)
>>> C++ does not have numeric for, so it doesn't count either.
>>>
>>> Francisco Olarte.
>>>
>> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>>
>> Looks like it does, it's just more flexible than Lua's.
> No 'for' is more flexible than Lua's.
>
> for a,b,c,as_many_as_you_like in myiter(anything) do
> end
>

Sorry, C++'s numeric for is more flexible than Lua, because it gives you
more control over the iteration.

You can also use rational objects which overload < and ++ in C++ numeric
fors, while you can't in Lua even with __add and __lt.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Dirk Laurie-2
2018-01-30 14:55 GMT+02:00 Soni "They/Them" L. <[hidden email]>:

>
>
> On 2018-01-30 10:51 AM, Dirk Laurie wrote:
>>
>> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>>
>>>
>>> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>>>>
>>>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
>>>> wrote:
>>>> ...
>>>>>
>>>>> Also, rationals are still numbers. They're just not "Lua numbers"
>>>>> (objects
>>>>> with type(x) == "number"). Any language with operator overloading (e.g.
>>>>> C++)
>>>>> lets me have numeric for with rationals. Except Lua. (Python doesn't
>>>>> have
>>>>> numeric for at all so it doesn't count.)
>>>>
>>>> C++ does not have numeric for, so it doesn't count either.
>>>>
>>>> Francisco Olarte.
>>>>
>>> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>>>
>>> Looks like it does, it's just more flexible than Lua's.
>>
>> No 'for' is more flexible than Lua's.
>>
>> for a,b,c,as_many_as_you_like in myiter(anything) do
>> end
>>
>
> Sorry, C++'s numeric for is more flexible than Lua, because it gives you
> more control over the iteration.
>
> You can also use rational objects which overload < and ++ in C++ numeric
> fors, while you can't in Lua even with __add and __lt.

C/C++ does not have a numeric for, it only has a generic for.

for (statement_list_1;statement_list_2;statement_list_3) do statement;

Nothing numeric about that.

No restriction anywhere, although if statement_list_2 is just an
assignment most compilers will recommend that you put it in
parentheses.

Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-30 11:04 AM, Dirk Laurie wrote:

> 2018-01-30 14:55 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>
>> On 2018-01-30 10:51 AM, Dirk Laurie wrote:
>>> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>>>
>>>> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>>>>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
>>>>> wrote:
>>>>> ...
>>>>>> Also, rationals are still numbers. They're just not "Lua numbers"
>>>>>> (objects
>>>>>> with type(x) == "number"). Any language with operator overloading (e.g.
>>>>>> C++)
>>>>>> lets me have numeric for with rationals. Except Lua. (Python doesn't
>>>>>> have
>>>>>> numeric for at all so it doesn't count.)
>>>>> C++ does not have numeric for, so it doesn't count either.
>>>>>
>>>>> Francisco Olarte.
>>>>>
>>>> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>>>>
>>>> Looks like it does, it's just more flexible than Lua's.
>>> No 'for' is more flexible than Lua's.
>>>
>>> for a,b,c,as_many_as_you_like in myiter(anything) do
>>> end
>>>
>> Sorry, C++'s numeric for is more flexible than Lua, because it gives you
>> more control over the iteration.
>>
>> You can also use rational objects which overload < and ++ in C++ numeric
>> fors, while you can't in Lua even with __add and __lt.
> C/C++ does not have a numeric for, it only has a generic for.
>
> for (statement_list_1;statement_list_2;statement_list_3) do statement;
>
> Nothing numeric about that.
>
> No restriction anywhere, although if statement_list_2 is just an
> assignment most compilers will recommend that you put it in
> parentheses.
>

We can argue about this all day but if I can do, in C++

for (type i = min; i < max; i += step) {
}

Why can't I do

for i=min,max,step do
end

in Lua? They should be equivalent.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Charles Heywood
I am confused on why you think you can't:

Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> function one() return 1 end
> function two() return 2 end
> function ten() return 10 end
> for i=one(), ten(), two() do print(i) end
1
3
5
7
9
>

On Tue, Jan 30, 2018 at 7:08 AM Soni "They/Them" L. <[hidden email]> wrote:


On 2018-01-30 11:04 AM, Dirk Laurie wrote:
> 2018-01-30 14:55 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>
>> On 2018-01-30 10:51 AM, Dirk Laurie wrote:
>>> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
>>>>
>>>> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>>>>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
>>>>> wrote:
>>>>> ...
>>>>>> Also, rationals are still numbers. They're just not "Lua numbers"
>>>>>> (objects
>>>>>> with type(x) == "number"). Any language with operator overloading (e.g.
>>>>>> C++)
>>>>>> lets me have numeric for with rationals. Except Lua. (Python doesn't
>>>>>> have
>>>>>> numeric for at all so it doesn't count.)
>>>>> C++ does not have numeric for, so it doesn't count either.
>>>>>
>>>>> Francisco Olarte.
>>>>>
>>>> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>>>>
>>>> Looks like it does, it's just more flexible than Lua's.
>>> No 'for' is more flexible than Lua's.
>>>
>>> for a,b,c,as_many_as_you_like in myiter(anything) do
>>> end
>>>
>> Sorry, C++'s numeric for is more flexible than Lua, because it gives you
>> more control over the iteration.
>>
>> You can also use rational objects which overload < and ++ in C++ numeric
>> fors, while you can't in Lua even with __add and __lt.
> C/C++ does not have a numeric for, it only has a generic for.
>
> for (statement_list_1;statement_list_2;statement_list_3) do statement;
>
> Nothing numeric about that.
>
> No restriction anywhere, although if statement_list_2 is just an
> assignment most compilers will recommend that you put it in
> parentheses.
>

We can argue about this all day but if I can do, in C++

for (type i = min; i < max; i += step) {
}

Why can't I do

for i=min,max,step do
end

in Lua? They should be equivalent.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


--
--
Ryan | Charles <[hidden email]>
Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Soni "They/Them" L.


On 2018-01-30 12:48 PM, Charles Heywood wrote:

> I am confused on why you think you can't:
>
> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> > function one() return 1 end
> > function two() return 2 end
> > function ten() return 10 end
> > for i=one(), ten(), two() do print(i) end
> 1
> 3
> 5
> 7
> 9
> >

Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
 > meta = {__add=function(x, y) return setmetatable({i=x.i + y.i}, meta)
end, __lt=function(x, y) return x.i < y.i end}
 > function one() return setmetatable({i=1}, meta) end
 > function two() return setmetatable({i=2}, meta) end
 > function ten() return setmetatable({i=10}, meta) end
 > for i=one(), two(), ten() do print(i) end
stdin:1: 'for' limit must be a number
stack traceback:
     stdin:1: in main chunk
     [C]: in ?
 > local i,j,k=one(), ten(), two() while i < j do print(i) i = i + k end
table: 0x558de8c74080
table: 0x558de8c74200
table: 0x558de8c747b0
table: 0x558de8c74890
table: 0x558de8c74970
 > local i,j,k=one(), ten(), two() while i < j do print(i.i) i = i + k end
1
3
5
7
9

Rationals don't work. Only floats and ints do. This sucks.

>
> On Tue, Jan 30, 2018 at 7:08 AM Soni "They/Them" L. <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>
>     On 2018-01-30 11:04 AM, Dirk Laurie wrote:
>     > 2018-01-30 14:55 GMT+02:00 Soni "They/Them" L.
>     <[hidden email] <mailto:[hidden email]>>:
>     >>
>     >> On 2018-01-30 10:51 AM, Dirk Laurie wrote:
>     >>> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L.
>     <[hidden email] <mailto:[hidden email]>>:
>     >>>>
>     >>>> On 2018-01-30 06:58 AM, Francisco Olarte wrote:
>     >>>>> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L.
>     <[hidden email] <mailto:[hidden email]>>
>     >>>>> wrote:
>     >>>>> ...
>     >>>>>> Also, rationals are still numbers. They're just not "Lua
>     numbers"
>     >>>>>> (objects
>     >>>>>> with type(x) == "number"). Any language with operator
>     overloading (e.g.
>     >>>>>> C++)
>     >>>>>> lets me have numeric for with rationals. Except Lua.
>     (Python doesn't
>     >>>>>> have
>     >>>>>> numeric for at all so it doesn't count.)
>     >>>>> C++ does not have numeric for, so it doesn't count either.
>     >>>>>
>     >>>>> Francisco Olarte.
>     >>>>>
>     >>>> for (int i = 0; i < 100; i++) { printf("%d\n", i); }
>     >>>>
>     >>>> Looks like it does, it's just more flexible than Lua's.
>     >>> No 'for' is more flexible than Lua's.
>     >>>
>     >>> for a,b,c,as_many_as_you_like in myiter(anything) do
>     >>> end
>     >>>
>     >> Sorry, C++'s numeric for is more flexible than Lua, because it
>     gives you
>     >> more control over the iteration.
>     >>
>     >> You can also use rational objects which overload < and ++ in
>     C++ numeric
>     >> fors, while you can't in Lua even with __add and __lt.
>     > C/C++ does not have a numeric for, it only has a generic for.
>     >
>     > for (statement_list_1;statement_list_2;statement_list_3) do
>     statement;
>     >
>     > Nothing numeric about that.
>     >
>     > No restriction anywhere, although if statement_list_2 is just an
>     > assignment most compilers will recommend that you put it in
>     > parentheses.
>     >
>
>     We can argue about this all day but if I can do, in C++
>
>     for (type i = min; i < max; i += step) {
>     }
>
>     Why can't I do
>
>     for i=min,max,step do
>     end
>
>     in Lua? They should be equivalent.
>
>     --
>     Disclaimer: these emails may be made public at any given time,
>     with or without reason. If you don't agree with this, DO NOT REPLY.
>
>
> --
> --
> Ryan | Charles <[hidden email] <mailto:[hidden email]>>
> Software Developer / System Administrator
> https://hashbang.sh

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Paige DePol
In reply to this post by Soni "They/Them" L.
Soni They/Them L. <[hidden email]> wrote:
>
> We can argue about this all day but if I can do, in C++

Sometimes I think you make posts like these to argue, Soni! ;)


> for (type i = min; i < max; i += step) {
> }
>
> Why can't I do
>
> for i=min,max,step do
> end
>
> in Lua? They should be equivalent.

Because C/C++ isn't Lua and Lua isn't C/C++ is the usual answer!

~Paige


Reply | Threaded
Open this post in threaded view
|

Re: Numeric for loop with rationals

Sean Conner
In reply to this post by Dirk Laurie-2
It was thus said that the Great Dirk Laurie once stated:

> 2018-01-30 14:23 GMT+02:00 Soni "They/Them" L. <[hidden email]>:
> >
> >
> > On 2018-01-30 06:58 AM, Francisco Olarte wrote:
> >>
> >> On Tue, Jan 30, 2018 at 1:11 AM, Soni "They/Them" L. <[hidden email]>
> >> wrote:
> >> ...
> >>>
> >>> Also, rationals are still numbers. They're just not "Lua numbers"
> >>> (objects
> >>> with type(x) == "number"). Any language with operator overloading (e.g.
> >>> C++)
> >>> lets me have numeric for with rationals. Except Lua. (Python doesn't have
> >>> numeric for at all so it doesn't count.)
> >>
> >> C++ does not have numeric for, so it doesn't count either.
> >>
> >> Francisco Olarte.
> >>
> >
> > for (int i = 0; i < 100; i++) { printf("%d\n", i); }
> >
> > Looks like it does, it's just more flexible than Lua's.
>
> No 'for' is more flexible than Lua's.
>
> for a,b,c,as_many_as_you_like in myiter(anything) do
> end

  Oh, you mean something like:

        function range(low,high,inc)
          inc = inc or 1
       
          local function bump()    
            local r = low
            low     = low + inc
            if r <= high then
              return r
            end
          end
       
          return bump              
        end

which respects __add and __le so something like

        for x in range(r(1,10),r(10,10),r(1,10)) do
          print(x)
        end

will work?  Neat!

  -spc


12