V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
prasanta
V2EX  ›  程序员

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

  •  
  •   prasanta · 2019-08-07 23:15:58 +08:00 · 567 次点击
    这是一个创建于 1733 天前的主题,其中的信息可能已经有所发展或是发生改变。

    注:还没实现,大量参考 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
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1039 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 18:08 · PVG 02:08 · LAX 11:08 · JFK 14:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.