# 安裝
sudo apt install tealang
sudo brew install tealang
sudo yum install tealang
# 運行
tea run app.tea
tea install dependency
# 引入依賴
import
http
os
# 賦值與數據類型
a1 = 1 # 整數
a2 = "a" # 字符串
a3 = true # 布爾
a4 = null # 空
a5 = 1.1 # 浮點
a6 = [a1 a2 a3] # 列表
a7 = {name: "Elliot" age:26} # 字典
a8 = (a1 a2 a3) # 元組
a9 = {a1 a2 a3} # 集合
# 基本運算
+,-,*,/,%,^,&,|,!,==,>=,<=,>,<,~,?
# 函數
hello name: "Hello {name}"
default : "Hello World"
main arg1 arg2...:
print arg1
print arg2
# 類
Myclass object:
attibute = "class attibute"
__init name:
.name = name
._private = 1
__str:.name
show:.name
# 判斷
i = 0
if i == 0
hello i
elif 20 > i > 10
default
else
exit
# 循環
for i ~ 0:10 print i
for k v ~ {"name": "Elliot"}
print k
print v
# 推導式
print i for i ~ ["a" "b" "c" "d"]
print i for i ~ 0:10
0:10:2 = [0 2 4 6 8]
# 數組切片
[0 1 2 3 4 5][0:2] = [0 1]
[0 1 2 3 4 5][-2:-0] = [4 5]
# 異步函數
async callme: "Async Hello World"
await [callme callme callme callme]
# 解構賦值
theBait = 1000
theSwitch = 0
[theBait theSwitch] = [theSwitch theBait]
futurists = {
sculptor:"Umberto Boccioni"
painter:"Vladimir Burliuk"
poet: {
name:"Tom"
address:["Via Roma 42R" "Bellagio, Italy 22021"]
}
}
{poet: {name, address: [street, city]}} = futurists
tag = "<impossible>"
[open contents... close] = tag.split
# 異常捕獲
try
something
catch ValueError
print "Value is wrong."
catch CustomError
print "CustomError"
else
print error
finally
anything