From c4d9500e7a56580aad403d0dab086b1e39ec2f75 Mon Sep 17 00:00:00 2001 From: Daniel Kang Date: Sat, 12 Jan 2019 18:26:07 -0800 Subject: [PATCH] add example --- cmd/example/main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cmd/example/main.go diff --git a/cmd/example/main.go b/cmd/example/main.go new file mode 100644 index 0000000..85c0ddb --- /dev/null +++ b/cmd/example/main.go @@ -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) + } +}