{"id":41621741,"url":"https://github.com/jobs-github/escript","last_synced_at":"2026-01-24T13:55:52.821Z","repository":{"id":49498724,"uuid":"517720928","full_name":"jobs-github/escript","owner":"jobs-github","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-24T15:11:15.000Z","size":326,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T05:13:05.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jobs-github.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":"2022-07-25T15:30:00.000Z","updated_at":"2023-03-30T13:18:54.000Z","dependencies_parsed_at":"2024-06-20T04:43:01.147Z","dependency_job_id":null,"html_url":"https://github.com/jobs-github/escript","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jobs-github/escript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobs-github%2Fescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobs-github%2Fescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobs-github%2Fescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobs-github%2Fescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jobs-github","download_url":"https://codeload.github.com/jobs-github/escript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobs-github%2Fescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28729411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-24T13:55:52.761Z","updated_at":"2026-01-24T13:55:52.815Z","avatar_url":"https://github.com/jobs-github.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp id=\"id_top\"\u003e\u003c/p\u003e\n\n- [escript - an embedded script for Go](#escript---a-embedded-script-for-go)\n  - [Features](#features)\n  - [Quick Start](#quick-start)\n    - [run interactive interpreter](#run-interactive-interpreter)\n    - [run scripts](#run-scripts)\n    - [conditional expression](#conditional-expression)\n    - [recursion](#recursion)\n    - [closure](#closure)\n    - [eval](#eval)\n    - [embedded eval](#embedded-eval)\n    - [dump \\\u0026 load AST as json](#dump--load-ast-as-json)\n  - [builtin function](#builtin-function)\n    - [type](#type)\n    - [str](#str)\n    - [print](#print)\n    - [println](#println)\n    - [printf](#printf)\n    - [sprintf](#sprintf)\n    - [loads](#loads)\n    - [dumps](#dumps)\n    - [loop](#loop)\n    - [map](#map)\n    - [reduce](#reduce)\n    - [filter](#filter)\n    - [range](#range)\n  - [types](#types)\n    - [null](#null)\n    - [boolean](#boolean)\n    - [integer](#integer)\n    - [string](#string)\n    - [array](#array)\n    - [hash](#hash)\n    - [builtin](#builtin)\n    - [function](#function)\n    - [method](#method)\n  - [License](#license)\n  - [Author](#author)\n  - [More](#more)\n\n# escript - an embedded script for Go #\n\nescript is a tiny, expression-based embedded language for Go.\n\n    package main\n\n    import (\n        \"fmt\"\n        \"github.com/jobs-github/escript\"\n    )\n\n    func main() {\n        code := `const r = (1 \u003e 0) ? (1 + 1) : (10 % 3); println(r);`\n        r, _ := escript.NewState(code)\n        res, _ := r.Run(nil)\n        fmt.Println(res)\n    }\n\n[back to top](#id_top)\n\n## Features ##\n\n* go-like syntax (also borrow some from python/c)\n* variable bindings\n* arithmetic expressions\n* built-in functions\n* first-class and higher-order functions (closure)\n* conditional expression\n* object member call\n* eval AST\n* dump \u0026 load AST as json\n* data types\n    * integer\n    * boolean\n    * string\n    * array\n    * hash\n\n[back to top](#id_top)\n\n## Quick Start ##\n\n### run interactive interpreter ###\n\n    chmod +x /make.sh\n    ./make.sh\n    ./escript\n\n    \n**Note** : you can change `useVM` in `repl/main.go` to choose default interpreter.  \n\n[back to top](#id_top)\n\n### run scripts ###\n\n    chmod +x /make.sh\n    ./make.sh\n    ./escript scripts/hello.es\n\n[back to top](#id_top)\n\n### [conditional expression](scripts/conditional.es) ###\n\n    (1 \u003e 0) ? (1 + 1) : (10 % 3)\n\n[back to top](#id_top)\n\n### [recursion](scripts/mapreduce.es) ###\n\n    func map_iter(arr, accumulated, fn) {\n        (arr.len() == 0) ? accumulated : map_iter(arr.tail(), accumulated.push(fn(arr.first())), fn);\n    };\n    func my_map(arr, fn) {\n        map_iter(arr, [], fn);\n    };\n    func double(x) {\n        x * 2;\n    };\n\n    func my_reduce(arr, result, fn) {\n        (arr.len() == 0) ? result : my_reduce(arr.tail(), fn(result, arr.first()), fn);\n    };\n    func add(x, y) {\n        x + y;\n    };\n    func sum(arr) {\n        my_reduce(arr, 0, add);\n    };\n\n    const a = [1,2,3,4,5];\n    const result = my_map(a, double);\n    println(result);\n\n    const rc = sum([1,2,3,4,5]);\n    println(rc);\n\n[back to top](#id_top)\n\n### [closure](scripts/closure.es) ###\n\n    const r = func (x) {\n        x * 2;\n    }(2);\n\n    println(r);\n\n    func add(x) {\n        func(y) {\n            x + y;\n        };\n    };\n\n    const fn = add(1);\n    println(fn(2));\n\n[back to top](#id_top)\n\n### eval ###\n\n    package main\n\n    import (\n        \"fmt\"\n        \"github.com/jobs-github/escript\"\n    )\n\n    func main() {\n        code := `const r = (1 \u003e 0) ? (1 + 1) : (10 % 3); println(r);`\n        r, _ := escript.NewState(code)\n        res, _ := r.Run(nil)\n        fmt.Println(res)\n    }\n\n[back to top](#id_top)\n\n### embedded eval ###\n\n    package main\n\n    import (\n        \"fmt\"\n        \"github.com/jobs-github/escript\"\n        \"github.com/jobs-github/escript/object\"\n    )\n\n    func main() {\n        T := func() (object.Object, error) { return object.True, nil }\n        F := func() (object.Object, error) { return object.False, nil }\n        r, _ := escript.NewState(`($a || $b) \u0026\u0026 ($c || $d);`)\n        res, _ := r.Run(object.Symbols{\"a\": T, \"b\": T, \"c\": T, \"d\": F})\n        fmt.Println(res)\n    }\n\n### dump \u0026 load AST as json ###\n\ndump AST as json:  \n\n    chmod +x /make.sh\n    ./make.sh\n    ./escript --dump scripts/conditional.es \u003e scripts/conditional.json\n\nload \u0026 eval AST from json:  \n\n    chmod +x /make.sh\n    ./make.sh\n    ./escript --load scripts/conditional.json\n\n[back to top](#id_top)\n\n## [builtin function](builtin/builtin.go) ##\n\n### type ###\n\n    const s = \"EOF\";\n    println(type(s));\n\n[back to top](#id_top)\n\n### str ###\n\n    const arr = [1,2,3];\n    println(str(arr));\n\n[back to top](#id_top)\n\n### print ###\n\n    print(\"123 \", 456, \" \", [7,8,9]);\n\n[back to top](#id_top)\n\n### println ###\n\n    println(\"aaa \", 111, \" \", {\"k1\": 1, \"k2\": \"2\"});\n\n[back to top](#id_top)\n\n### printf ###\n\n    const testi = 999;\n    const tests = \"2022\";\n    printf(\"%v\\n%v\\n\", testi, tests);\n\n[back to top](#id_top)\n\n### sprintf ###\n\n    const testi2 = 9999;\n    const tests2 = \"2222\";\n    const ms = sprintf(\"%v-%v\", testi, tests);\n    println(ms);\n\n[back to top](#id_top)\n\n### [loads](scripts/json.es) ###\n\n    const s = \"{\\\"k3\\\":{\\\"k31\\\":true,\\\"k32\\\":[1,2,3]},\\\"k2\\\":\\\"2\\\",\\\"k1\\\":1}\"; \n    const obj = loads(s);\n    println(obj);\n\n[back to top](#id_top)\n\n### [dumps](scripts/json.es) ###\n\n    const obj1 = { \"k1\": null, \"k2\": 123 };\n    const objstr = dumps(obj1);\n    println(objstr);\n\n### [loop](scripts/loop.es) ###\n\n    loop(10, func(i){\n        i \u003c 5 ? println(i) : println(i * i)\n    });\n\n### [map](scripts/array.es) ###\n\n    const arr = [1,2,3];\n    const r = map(arr, func(i, item) { item * 2 });\n    println(r);\n\n### [reduce](scripts/array.es) ###\n\n    const arr = [1,2,3];\n    const acc = reduce(arr, func(x, y) { x + y }, 0);\n    println(acc);\n\n### [filter](scripts/array.es) ###\n\n    const arr = [1,2,3];\n    const fr = filter(arr, func(i, item) { item \u003e 1 });\n    println(fr);\n\n### [range](scripts/array.es) ###\n\n    println(range(10, func(i) { \n        sprintf(\"key_%v\", (i % 2 == 0) ? i * 2 : i)\n    }));\n\n[back to top](#id_top)\n\n## [types](object/def.go) ##\n\n### [null](object/null.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\n\n    \u003e\u003e const n = null;\n    \u003e\u003e n.not();\n    true\n    \u003e\u003e !n;\n    true\n\n[back to top](#id_top)\n\n### [boolean](object/boolean.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\nneg|-\nint     |convert to int\n\n    \u003e\u003e const b = true;\n    true\n    \u003e\u003e b.not()\n    false\n    \u003e\u003e b.neg()\n    -1\n    \u003e\u003e b.int()\n    1\n    \u003e\u003e !b\n    false\n    \u003e\u003e -b\n    -1\n\n[back to top](#id_top)\n\n### [integer](object/integer.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\nneg|-\nint     |convert to int\n\n    \u003e\u003e const i = 123\n    123\n    \u003e\u003e i.not()\n    false\n    \u003e\u003e i.neg()\n    -123\n    \u003e\u003e i.int()\n    123\n    \u003e\u003e !i\n    false\n    \u003e\u003e -i\n    -123\n\n[back to top](#id_top)\n### [string](object/string.go) ###\n\nmethod  |comment\n--------|-------\nlen     |length of string\nindex   |get value by index\nnot     |!\nint     |convert to int\n\n    \u003e\u003e const s = \"123\"\n    123\n    \u003e\u003e s.len()\n    3\n    \u003e\u003e s.index(1)\n    2\n    \u003e\u003e s.not()\n    false\n    \u003e\u003e s.int()\n    123\n    \u003e\u003e s[1]\n    2\n    \u003e\u003e !s\n    false\n\n[back to top](#id_top)\n### [array](object/array.go) ###\n\nmethod  |comment\n--------|-------\nlen     |length of array\nindex   |get value by index\nnot     |!\nfirst   |first value\nlast    |last value\ntail    |remove first value and return rest\npush    |append value\n\n    \u003e\u003e const arr = [1,2,3,4,5]\n    [1, 2, 3, 4, 5]\n    \u003e\u003e arr.push(\"hello\")\n    [1, 2, 3, 4, 5, hello]\n    \u003e\u003e arr.len()\n    6\n    \u003e\u003e arr[0]\n    1\n    \u003e\u003e arr.not()\n    false\n    \u003e\u003e !arr\n    false\n    \u003e\u003e arr.first()\n    1\n    \u003e\u003e arr.last()\n    hello\n    \u003e\u003e arr.tail()\n    [2, 3, 4, 5, hello]\n\n[back to top](#id_top)\n\n### [hash](object/hash.go) ###\n\nmethod  |comment\n--------|-------\nlen     |length of hash pairs\nindex   |get value by key\nkeys    |get keys\nnot     |!\n\n    \u003e\u003e const h = {\"k1\": 1, \"k2\": \"bbb\", \"k3\": [1,2,3]}\n    {k1: 1, k2: bbb, k3: [1, 2, 3]}\n    \u003e\u003e h[\"k1\"]\n    1\n    \u003e\u003e h.len()\n    3\n    \u003e\u003e h.not()\n    false\n    \u003e\u003e h.index(\"k1\")\n    1000\n    \u003e\u003e !h\n    false\n    \u003e\u003e h.keys()\n    [k1, k2, k3]\n\n[back to top](#id_top)\n\n### [builtin](object/builtin.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\n\n    \u003e\u003e const t = type\n    \u003cbuilt-in function type\u003e\n    \u003e\u003e const s = \"123\"\n    123\n    \u003e\u003e t(s)\n    string\n    \u003e\u003e t.not()\n    false\n    \u003e\u003e !t\n    false\n\n[back to top](#id_top)\n### [function](object/function.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\n\n    \u003e\u003e const fn = func(x, y) { x + y; }\n    closure[0xc000425260]\n    \u003e\u003e fn(1,2)\n    3\n    \u003e\u003e !fn\n    false\n    \u003e\u003e fn.not()\n    false\n\n[back to top](#id_top)\n### [method](object/objectfunc.go) ###\n\nmethod  |comment\n--------|-------\nnot     |!\n\n    \u003e\u003e const arr = [1,2,3]\n    [1, 2, 3]\n    \u003e\u003e const fn = arr.index\n    \u003cbuilt-in method index of array object\u003e\n    \u003e\u003e fn(1)\n    2\n    \u003e\u003e !fn\n    false\n    \u003e\u003e fn.not()\n    false\n    \u003e\u003e const l = arr.len\n    \u003cbuilt-in method len of array object\u003e\n    \u003e\u003e l()\n    3\n\n[back to top](#id_top)\n\n## License ##\n\nescript is licensed under [New BSD License](https://opensource.org/licenses/BSD-3-Clause), a very flexible license to use.\n\n[back to top](#id_top)\n\n## Author ##\n\n* chengzhuo (jobs, yao050421103@163.com)  \n\n[back to top](#id_top)\n\n## More ##\n\n- [Writing A Compiler In Go](https://compilerbook.com/)  \n\n[back to top](#id_top)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjobs-github%2Fescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjobs-github%2Fescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjobs-github%2Fescript/lists"}