lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 10/10/2019 00:03, Soni "They/Them" L. wrote:
> 
> if select('#',...) was built into the language instead of being a C-ism
> (as in, something that leaks C API details) then for loops could've just
> stopped on no value.
> 

Kinda related, and Just spitballing here: Been wondering if tuples
should be fully supported in Lua. We already have the ... operator, that
kinda acts like it, why not go all in?

 > local tup = make_tuple('a', nil, 3)  -- imagine better syntax here

 > =tup[1]
 a

 >#tup
 3

 > local x,y,z = tup
 > =x,y,z
 a    nil   3

 > local tup_copy = return tup
 > =#tup_copy
 3

 >tup[2] = 'foo'
 * Error: Tuples are read only

 > local pi = make_tuple(3.1425)  -- consts ;)

 > for x in tup do print(x); end
 a
 nil
 3

Maybe do car and cdr functions too :)

Scott