{"id":22994799,"url":"https://github.com/movsb/taolang","last_synced_at":"2025-08-13T22:31:53.356Z","repository":{"id":79716210,"uuid":"43075058","full_name":"movsb/taolang","owner":"movsb","description":"The Tao Programming Language.","archived":false,"fork":false,"pushed_at":"2024-07-28T19:45:09.000Z","size":1129,"stargazers_count":33,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-03T21:00:49.235Z","etag":null,"topics":["javascript","programming-language","tao","taolang"],"latest_commit_sha":null,"homepage":"https://movsb.github.io/taolang/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/movsb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-24T15:20:38.000Z","updated_at":"2025-03-02T22:24:10.000Z","dependencies_parsed_at":"2023-04-07T23:07:06.609Z","dependency_job_id":null,"html_url":"https://github.com/movsb/taolang","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/movsb/taolang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movsb%2Ftaolang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movsb%2Ftaolang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movsb%2Ftaolang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movsb%2Ftaolang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/movsb","download_url":"https://codeload.github.com/movsb/taolang/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/movsb%2Ftaolang/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270329156,"owners_count":24565772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","programming-language","tao","taolang"],"created_at":"2024-12-15T05:20:25.146Z","updated_at":"2025-08-13T22:31:53.032Z","avatar_url":"https://github.com/movsb.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# taolang\n\nA Javascript-like dynamic language.\n\n## Grammar\n\n## Syntax\n\n### 变量定义\n\n```js\nlet a;          // 变量定义，值为 nil\nlet b = nil;    // nil 是空类型\nlet c = true;   // 布尔变量\nlet d = 123;    // 数值类型，内部类型为 int\nlet e = \"str\";  // 字符串类型（原始字符串）\nlet f = function(x,y,z) {return x+y*z;};        // 函数类型，可以直接当表达式使用\nlet g = function() {return \"test\"+\"str\";}();    // 函数作为表达式，定义后可以直接调用\nlet h = {       // 定义一个对象\n    a: nil,\n    b: 1,\n    c: \"cc\",\n    d: true,\n    e: function() {print(\"e\");},\n    f: {\n        xxx: \"this is xxx\",\n    },\n    g: function () {\n        return \"d\";\n    },\n    h: function() {\n        return {\n            what: \"what\",\n            when: \"when\",\n            \"who?\": \"who?\",\n        };\n    },\n};\n```\n\n### 函数定义\n\n全局函数或具名函数：\n\n```js\nfunction name(x,y,z) {\n\n}\n```\n\n函数作为表达式赋值：\n\n```js\nfunction name() {\n    let f = function() {\n\n    };\n}\n```\n\n函数作为回调函数：\n\n```js\nfunction sync(callback,a,b,c) {\n    return callback(a,b,c);\n}\n\nfunction main() {\n    print(\n        sync(\n            function(x,y,z) {\n                return x+y*z;\n            },\n            2,3,4\n        )\n    );\n}\n```\n\n### 代码块 \u0026 作用域\n\n仅支持词法作用域，不支持 Javascript 的函数作用域。\n\n```js\nfunction main() {\n    let a = 1;\n    {\n        let a = 2;\n        println(\"inner a: \", a); // 2\n        // return a;\n    }\n    println(\"outer a: \", a); // 1\n}\n```\n\n### 闭包\n\n```js\nfunction createCounter() {\n    let a = 0;\n    return function() {\n        a = a + 1;\n        return a;\n    };\n}\n\nfunction main() {\n    let c1 = createCounter();\n    let c2 = createCounter();\n    println(c1()); // 1\n    println(c1()); // 2\n    println(c2()); // 1\n    println(c2()); // 2\n}\n```\n\n### 对象定义与访问\n\n```js\nfunction main() {\n    let x = {\n        a: nil,\n        b: 1,\n        c: \"cc\",\n        d: true,\n        e: function() {print(\"e\");},\n        f: {\n            xxx: \"this is xxx\",\n        },\n        g: function () {\n            return \"d\";\n        },\n        h: function() {\n            return {\n                what: \"what\",\n                when: \"when\",\n                \"who?\": \"who?\",\n            };\n        },\n    };\n    println(x);\n    println(x.a);\n    println(x.b);\n    println(x[\"c\"]);\n    println(x[x.g()]);\n    println(x.e);\n    println(x.f.xxx);\n    println(x.h().what);\n    println(x.h()[\"who?\"]);\n    println(x.y);\n}\n```\n\n### 数组定义与访问\n\n```js\nfunction main() {\n    let a = [1,true,nil,\"str\",{},1+2*3,];\n    println(a);\n    println(a.length);\n    println(a[3]);\n    println([9][0]);\n}\n\nfunction main2() {\n    let a = [1,2,3,4,5,6,7,8];\n    let n = a.length-1;\n    for n \u003e= 0 {\n        println(a[n]);\n        n = n - 1;\n    }\n}\n```\n\n### Lambda表达式与函数式编程\n\n```js\nfunction each() {\n    let a = [1,3,5,7,9];\n    a.each(e=\u003eprintln(e));\n}\n\nfunction map() {\n    let a = [1,3,5,7,9];\n    let b = a.map(x=\u003ex*x);\n    println(b);\n}\n\nfunction reduce() {\n    let a = [1,2,3];\n    let b = a.reduce((memo,num)=\u003ememo+num,0);\n    println(b);\n}\n\nfunction find() {\n    let a = [1,3,5,7,9];\n    let b = a.find(x=\u003ex\u003e5);\n    println(b);\n}\n\nfunction filter() {\n    let a = [1,2,3,4,5,6,7,8,9];\n    let b = a.filter(x=\u003ex%2==0);\n    println(b);\n}\n\nfunction where() {\n    let a = [\n        {a:1,b:3},\n        {a:2,b:2},\n        {a:3,b:1},\n    ];\n    let b = a.where(x=\u003ex.a==1||x.b==1);\n    println(b);\n}\n```\n\n### 控制语句\n\n#### for 循环\n\n表达式部分不用 `()` 括起来。\n\n```js\nfunction main() {\n    let a = [1,2,3,4,5];\n    for let i=0; i\u003ca.length; i=i+1 {\n        println(a[i]);\n    }\n    let b = 3;\n    for {\n        println(b);\n        b = b-1;\n        if b \u003c -10 {\n            break;\n        }\n    }\n}\n```\n\n### if-else 控制语句\n\n```js\nfunction If() {\n    if 1 \u003e 0 {\n        println(\"1 \u003e 0\");\n    }\n\n    if 1 \u003e 2 {\n        println(\"1 \u003e 2\");\n    } else {\n        println(\"else 1 \u003e 2\");\n    }\n\n    if 1 \u003e 2 {\n        println(\"1 \u003e 2\");\n    } else if 2 \u003e 3 {\n        println(\"2 \u003e 3\");\n    } else {\n        println(\"else\");\n    }\n}\n\nfunction Break() {\n    let a = 10;\n    for a \u003e 0 {\n        if a == 5 {\n            break;\n        }\n        a= a-5;\n    }\n    print(a);\n}\n\nfunction Return() {\n    let a = 10;\n    for a \u003e 0 {\n        if a == 8 {\n            return a;\n        }\n        a = a- 1;\n    }\n}\n\nfunction main() {\n    If();\n    Break();\n    println(Return());\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmovsb%2Ftaolang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmovsb%2Ftaolang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmovsb%2Ftaolang/lists"}