mirror of
https://github.com/erg-lang/erg.git
synced 2025-12-23 05:36:48 +00:00
37 lines
650 B
Python
37 lines
650 B
Python
f {.x; .y}, [_], (_, _) = x + y
|
|
|
|
x = f {.x = 1; .y = 2}, [3], (4, 5)
|
|
assert x == 3
|
|
|
|
g _: Int = None
|
|
g 10
|
|
|
|
h _: Int, _: Int = None
|
|
h 10, 20
|
|
|
|
y = match [1, 2]:
|
|
[1, 2, 3] -> 6
|
|
[x, 2] -> x
|
|
assert y == 1
|
|
a = match { .x = 1 }:
|
|
{ y; } -> y + 100
|
|
{ x; y } -> 200 + x + y
|
|
{ x; } -> x
|
|
assert a == 1
|
|
b = match { .x = [1, 2]; }:
|
|
{ y; } -> y + 100
|
|
{ x; y; } -> 200 + x + y
|
|
{ x = [1, y]; } -> y
|
|
assert b == 2
|
|
c = match [[1, 2], [3, 4]]:
|
|
[x, [3, 5]] -> x + 100
|
|
[x, y, z] => 200 + x + y + z
|
|
[[1, x], [3, y]] -> x + y
|
|
assert c == 6
|
|
|
|
#[
|
|
and: [Bool; 2] -> Bool
|
|
and [True, t] = t
|
|
and [_, _] = False
|
|
assert and [True, True]
|
|
]#
|