wow skylark go 实现的 Python 语法的配置语言

2017-10-04 10:43:50 +08:00
 freestyle

https://github.com/google/skylark

package main

import (
	"github.com/google/skylark"
	"log"
	"fmt"
)

func main() {
	script := `print("hello {}".format("world"))
print([i for i in range(10) if i%2==0])`
	thread := new(skylark.Thread)
	globals := make(skylark.StringDict)
	err := skylark.ExecFile(thread, "", script, globals)
	if err != nil {
		log.Fatalf("eval error:%s", err)
	}
	value, err := skylark.Eval(thread, "", "range(10)", globals)
	if err != nil {
		log.Fatalf("eval error:%s", err)
	}
	fmt.Printf("%T %v", value, value)
}

hello world
[0, 2, 4, 6, 8]
*skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]skylark.String "hello world"
1251 次点击
所在节点    Go 编程语言
3 条回复
freestyle
2017-10-04 10:56:44 +08:00
fix output:
```
hello world
[0, 2, 4, 6, 8]
*skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```
naomhan
2017-10-04 11:34:09 +08:00
Skylark in Go is an interpreter for Skylark, implemented in Go.

Skylark is a dialect of Python intended for use as a configuration language.
janxin
2017-10-06 10:15:49 +08:00
Skylark is a dialect of Python intended for use as a configuration language. Like Python, it is an untyped dynamic language with high-level data types, first-class functions with lexical scope, and garbage collection. Unlike CPython, independent Skylark threads execute in parallel, so Skylark workloads scale well on parallel machines.

这个可以做内嵌脚本系统用了

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

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

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

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

© 2021 V2EX