add example

This commit is contained in:
Daniel Kang 2019-01-12 18:26:07 -08:00
parent 8e56bd8218
commit c4d9500e7a

20
cmd/example/main.go Normal file
View 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)
}
}