moonscript/spec/inputs/destructure.moon

101 lines
1.1 KiB
Plaintext
Raw Normal View History

2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
do
{a, b} = hello
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{{a}, b, {c}} = hello
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{ :hello, :world } = value
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
do
{ yes: no, thing } = world
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{:a,:b,:c,:d} = yeah
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{a} = one, two
{b}, c = one
{d}, e = one, two
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
x, {y} = one, two
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
xx, yy = 1, 2
{yy, xx} = {xx, yy}
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{a, :b, c, :d, e, :f, g} = tbl
2012-11-28 07:46:32 +00:00
---
2013-06-07 02:33:08 +00:00
do
futurists =
sculptor: "Umberto Boccioni"
painter: "Vladimir Burliuk"
poet:
name: "F.T. Marinetti"
address: {
"Via Roma 42R"
"Bellagio, Italy 22021"
}
{poet: {:name, address: {street, city}}} = futurists
2012-11-28 07:46:32 +00:00
--
2013-06-07 02:33:08 +00:00
do
{ @world } = x
{ a.b, c.y, func!.z } = x
2012-11-28 07:46:32 +00:00
2013-06-07 02:33:08 +00:00
{ world: @world } = x
2012-11-28 07:46:32 +00:00
2012-11-29 08:37:49 +00:00
--
2013-06-07 02:33:08 +00:00
do
thing = {{1,2}, {3,4}}
2012-11-29 08:37:49 +00:00
2013-06-07 02:33:08 +00:00
for {x,y} in *thing
print x,y
2012-11-29 08:37:49 +00:00
--
2013-06-07 02:33:08 +00:00
do
with {a,b} = thing
print a, b
--
2013-06-07 02:33:08 +00:00
do
thing = nil
if {a} = thing
print a
else
print "nothing"
thang = {1,2}
if {a,b} = thang
print a,b
if {a,b} = thing
print a,b
elseif {c,d} = thang
print c,d
else
print "NO"
--
do
z = "yeah"
{a,b,c} = z
do
{a,b,c} = z
(z) ->
{a,b,c} = z
do
z = "oo"
(k) ->
{a,b,c} = z