mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
28 lines
503 B
Python
28 lines
503 B
Python
# Check that a parser can pass the advanced syntax
|
|
# 高度な文法をチェックする
|
|
|
|
# overloading (多重定義)
|
|
f x = 1 + x + 2
|
|
f x, y =
|
|
1 + x + y
|
|
f x, y, z =
|
|
1 + x + y + z
|
|
assert 4 == f 1
|
|
assert 4 == f 1, 1
|
|
assert 3 == f 1, 1, 1
|
|
|
|
# pattern overloading
|
|
fib 0 = 0
|
|
fib 1 = 1
|
|
fib(n: Nat) -> Nat = fib(n-1) + fib(n-2)
|
|
|
|
# keyword arguments (キーワード引数)
|
|
t = if True:
|
|
then: 1
|
|
else: 2
|
|
assert t == 1
|
|
|
|
# import
|
|
math = import "math"
|
|
# {*} = "math" # use all
|
|
{pi} = import "math"
|