mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 09:59:29 +00:00
Add destructuring assignement
This commit is contained in:
parent
851e9f89d6
commit
842536b561
10 changed files with 3823 additions and 2985 deletions
40
ideas.txt
40
ideas.txt
|
|
@ -6,7 +6,7 @@ To be implemented, theese need to:
|
|||
* are invalid vanilla Lua syntax.
|
||||
* are not ambigous with any vanilla Lua syntax.
|
||||
* be significantly useful compared to existing Candran/Lua code.
|
||||
* be useful without having to rewrite APIs specifically for Candran. Candran intends to make Lua easier, not supersede it.
|
||||
* be useful without having to rewrite APIs specifically for Candran. Candran intends to make Lua easier, not replace it.
|
||||
|
||||
Example rejected ideas:
|
||||
* Python-style function decorators (implemented in Candran 0.1.0):
|
||||
|
|
@ -37,6 +37,7 @@ end
|
|||
local a = new Thing()
|
||||
->
|
||||
(TODO: define how classes work. May even use ClassCommons)
|
||||
|
||||
Not very Lua-ey to impose how to make your classes?
|
||||
|
||||
* try / except|catch / finally / else / other keywords
|
||||
|
|
@ -48,6 +49,8 @@ finally
|
|||
clean()
|
||||
end
|
||||
|
||||
may be doable using if with assignement + pcall
|
||||
|
||||
* static type checking
|
||||
local a = externalFunc() -- unknown
|
||||
if a == "hey" then
|
||||
|
|
@ -70,20 +73,26 @@ local b = a[3:5:1]
|
|||
|
||||
is it actually useful? even in python I rarely use it, apart from extracting a row or column for a matrix (and we don't have >1D arrays in Lua so...)
|
||||
|
||||
OR return multiple value instead of a list?
|
||||
|
||||
or list of incices:
|
||||
local a, b, c = l[1, 2, 3]
|
||||
|
||||
how to handle hash table?
|
||||
local a, b, c = l.(a, b, c)
|
||||
or
|
||||
local a, b, c = l.a, .b, .c
|
||||
|
||||
but
|
||||
local a, b, c = l[1], [2], [3]
|
||||
conflicts with table comprehension: change or use .[n]?
|
||||
|
||||
or create some syntax akin to destructuring assignemnts but for numeric indexes:
|
||||
local [a, b, c] = t
|
||||
|
||||
* Destructuring assignment
|
||||
local pos = { x = 5, y = 12 }
|
||||
|
||||
local {x, y} = pos -- x, y = pos.x, pos.y
|
||||
local {a, b, x = x, y = y} = pos -- x, y = pos.x, pos.y, a = pos[1], b = pos[2]
|
||||
local {a, b, :x, :y} = pos -- shorthand for the above line. Or .x, .y
|
||||
local {:x.u} = pos OR {:x:u} OR {.x.u} -- u = pos.x.u
|
||||
local [x, y] = pos -- x, y = pos[0], pos[1]
|
||||
local x, y $= pos
|
||||
|
||||
And in implicit assignments:
|
||||
for i, {x, y} in ipairs(positions) do
|
||||
|
||||
Sounds useful, at least the key-value part.
|
||||
Allow recursive destructing assignements
|
||||
|
||||
* String interpolation
|
||||
Delimited by ``:
|
||||
|
|
@ -93,4 +102,7 @@ Also allows multi-line with this maybe?
|
|||
meh
|
||||
|
||||
* Other potential inspiration
|
||||
https://www.ruby-lang.org/fr/
|
||||
https://www.ruby-lang.org/
|
||||
|
||||
* Lua 5.4 stuff
|
||||
const, to-be-closed variables: they're fun but as of now the syntax is awful
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue