add example
This commit is contained in:
parent
8e56bd8218
commit
c4d9500e7a
1 changed files with 20 additions and 0 deletions
20
cmd/example/main.go
Normal file
20
cmd/example/main.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import "github.com/d5/tengo/script"
|
||||
|
||||
var code = `
|
||||
reduce := func(seq, fn) {
|
||||
s := 0
|
||||
for x in seq { fn(x, s) }
|
||||
return s
|
||||
}
|
||||
|
||||
print(reduce([1, 2, 3], func(x, s) { s += x }))
|
||||
`
|
||||
|
||||
func main() {
|
||||
s := script.New([]byte(code))
|
||||
if _, err := s.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue