[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 'in' keyword today (was Re: mathlib)
- From: Thomas Jericke <tjericke@...>
- Date: Wed, 09 Apr 2014 11:01:25 +0200
On 04/09/2014 10:22 AM, Dirk Laurie wrote:
2014-04-09 6:30 GMT+02:00 Coroutines <coroutines@gmail.com>:
I think I would suggest both an 'in' and 'from' so this would be possible:
local a, b, c in some_table
local t_concat, t_insert = concat, insert from table
The proposed 'from', on the other hand, is not too hard to imitate
in pure Lua.
local t_concat, t_insert = from(table,"concat,insert")
I don't think the impact is dramatic enough to justify another keyword.
I totally agree, a new keyword is not needed, but why not use the same
keyword for both cases
local a, b, c in some_table
local t_concat, t_insert = concat, insert in table
I am sure the parser will be able to distinguish a RHS "in" from a LHS
"in".
Actually:
local a, b, c in table
--expands to
local a, b, c = a, b, c in table
--expands to
local a, b, c = table.a, table.b, table.c
-- If "table" is an expression the expression gets evaluated only once.
Could all be done with a preprocessor :-) The last comment only at the
cost of a local.
local a, b, c = a, b, c in expression
--expands to
local temp_table = expression -- extra local needed
local a, b, c = temp_table.a, temp_table.b, temp_table.c
The next step would be allow functions:
local a, b, c = a, b, c in func, invariant
--expands to
local a, b, c = func(invariant, "a"), func(invariant, "b"),
func(invariant, "c")
Invariant could be for example a table and the function an additional check:
function get_assert(table, key)
return assert(table[key])
end
local sinh, cosh in get_assert, require "mathx"
So much fun!
I actually started to analyse the Lua code how I could do a patch for
this, but I don't have enough time to work on it currently.
--
Thomas
- References:
- Re: mathlib, Roberto Ierusalimschy
- Re: mathlib, steve donovan
- Re: mathlib, Christopher Berardi
- Re: mathlib, Sean Conner
- Re: mathlib, Coroutines
- Re: mathlib, Sean Conner
- Re: mathlib, Christopher Berardi
- Re: mathlib, steve donovan
- Re: mathlib, Coroutines
- Re: mathlib, steve donovan
- Re: mathlib, Coroutines
- 'in' keyword today (was Re: mathlib), Petite Abeille
- Re: 'in' keyword today (was Re: mathlib), Rena
- Re: 'in' keyword today (was Re: mathlib), Philipp Janda
- Re: 'in' keyword today (was Re: mathlib), Coroutines
- Re: 'in' keyword today (was Re: mathlib), Dirk Laurie