@@ -86,44 +86,45 @@ You execute lisp from Go code and get results from it back to Go. Example from [
8686
8787``` go
8888func ExampleEVAL () {
89- newEnv := env.NewEnv ()
90-
91- // Load required lisp libraries
92- for _ , library := range []struct {
93- name string
94- load func (newEnv types.EnvType ) error
95- }{
96- {" core mal" , nscore.Load },
97- {" core mal with input" , nscore.LoadInput },
98- {" command line args" , nscore.LoadCmdLineArgs },
99- {" core mal extended" , nscoreextended.Load },
100- {" assert" , nsassert.Load },
101- } {
102- if err := library.load (newEnv); err != nil {
103- log.Fatalf (" Library Load Error: %v " , err)
104- }
105- }
106-
107- // parse (READ) lisp code
108- ast , err := lisp.READ (` (+ 2 2)` , nil )
109- if err != nil {
110- log.Fatalf (" READ error: %v " , err)
111- }
112-
113- // eval AST
114- result , err := lisp.EVAL (ast, newEnv, nil )
115- if err != nil {
116- log.Fatalf (" EVAL error: %v " , err)
117- }
118-
119- // use result
120- if result.(int ) != 4 {
121- log.Fatalf (" Result check error: %v " , err)
122- }
123-
124- // optionally print resulting AST
125- fmt.Println (lisp.PRINT (result))
126- // Output: 4
89+ newEnv := env.NewEnv ()
90+
91+ // Load required lisp libraries
92+ for _ , library := range []struct {
93+ name string
94+ load func (newEnv types.EnvType ) error
95+ }{
96+ {" core mal" , nscore.Load },
97+ {" core mal with input" , nscore.LoadInput },
98+ {" command line args" , nscore.LoadCmdLineArgs },
99+ {" concurrent" , nsconcurrent.Load },
100+ {" core mal extended" , nscoreextended.Load },
101+ {" system" , nssystem.Load },
102+ } {
103+ if err := library.load (newEnv); err != nil {
104+ log.Fatalf (" Library Load Error %q : %v " , library.name , err)
105+ }
106+ }
107+
108+ // parse (READ) lisp code
109+ ast , err := lisp.READ (` (+ 2 2)` , nil , newEnv)
110+ if err != nil {
111+ log.Fatalf (" READ error: %v " , err)
112+ }
113+
114+ // eval AST
115+ result , err := lisp.EVAL (context.TODO (), ast, newEnv)
116+ if err != nil {
117+ log.Fatalf (" EVAL error: %v " , err)
118+ }
119+
120+ // use result
121+ if result.(int ) != 4 {
122+ log.Fatalf (" Result check error: %v " , err)
123+ }
124+
125+ // optionally print resulting AST
126+ fmt.Println (lisp.PRINT (result))
127+ // Output: 4
127128}
128129```
129130
0 commit comments