Tea: 我也设计了一门新的编程语言

2019-08-07 23:15:58 +08:00
 prasanta

注:还没实现,大量参考 python,golang,coffescript.

# 安装
sudo apt install tealang
sudo brew install tealang
sudo yum install tealang

# 运行
tea run app.tea

# 依赖管理

- teafile
- teafile.lock
- tea add dependency
- tea remove 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
575 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/589969

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX