历时一年,许式伟正式全球发布Go+1.0!
原创 局长 OSC开源社区 2021-10-18
静态类型语言。 与 Go 完全兼容。 脚本化的风格,以及比 Go 更易于阅读的数据科学代码。 支持字节码后端和 Go 代码生成。在字节码模式下,Go+ 不支持 cgo
。然而,在 Go 代码生成模式下,Go+ 完全支持cgo
。
Go+ 部分语言特性
{: , : } {: , : } {: , : } {}
[, ] [] [, ] [, , ] [] [, ] []
a := [x*x for x <- [1, 3, 5, 7, 11]]b := [x*x for x <- [1, 3, 5, 7, 11], x > 3]c := [i+v for i, v <- [1, 3, 5, 7, 11], i%2 == 1]d := [k+","+s for k, s <- {"Hello": "xsw", "Hi": "Go+"}] arr := [1, 2, 3, 4, 5, 6]e := [[a, b] for a <- arr, a < b for b <- arr, b > 2] x := {x: i for i, x <- [1, 3, 5, 7, 11]}y := {x: i for i, x <- [1, 3, 5, 7, 11], i%2 == 1}z := {v: k for k, v <- {1: "Hello", 3: "Hi", 5: "xsw", 7: "Go+"}, k > 3
{ } [{, }, {, }, {, }] , {x. , . } {x. , . } (, ) ()
{ } [{, }, {, }, {, }] { , . } { , . }
For 循环
sum := 0for x <- [1, 3, 5, 7, 11, 13, 17], x > 3 { sum += x}
}
// Gop_Enum(proc func(val ValType)) or:
// Gop_Enum(proc func(key KeyType, val ValType))
func (p *Foo) Gop_Enum(proc func(key int, val string)) {
// ...
}
foo := &Foo{}
for k, v := range foo {
println(k, v)
}
for k, v <- foo {
println(k, v)
}
println({v: k for k, v <- foo})
For range of UDT2
type FooIter struct {} // (Iterator) Next() (val ValType, ok bool) or:// (Iterator) Next() (key KeyType, val ValType, ok bool)func (p *FooIter) Next() (key int, val string, ok bool) { // ...} type Foo struct {} // Gop_Enum() Iteratorfunc (p *Foo) Gop_Enum() *FooIter { // ...} foo := &Foo{}for k, v := range foo { println(k, v)} for k, v <- foo { println(k, v)} println({v: k for k, v <- foo})
// ...
}
func plot2(fn func(x float64) (float64, float64)) {
// ...
}
plot(x => x * x) // plot(func(x float64) float64 { return x * x })
plot2(x => (x * x, x + x)) // plot2(func(x float64) (float64, float64) { return x * x, x + x })
{ big. } { {} } { {(big.).(., .)} } { ..(., .) } { {(big.).(.)} } () () ( ()) ()
END
赞 (0)