-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmal.go
More file actions
60 lines (51 loc) · 947 Bytes
/
mal.go
File metadata and controls
60 lines (51 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/poly2d/malgo/core"
"github.com/poly2d/malgo/eval"
"github.com/poly2d/malgo/model"
"github.com/poly2d/malgo/read"
)
func mRead(in string) model.MalForm {
return read.ReadStr(in)
}
func mEval(mf model.MalForm) model.MalForm {
return eval.EvalAst(mf, core.Env)
}
func mPrint(in model.MalForm) model.MalForm {
in.Print()
fmt.Println()
return in
}
func rep(in string) {
readRes := mRead(in)
if readRes.Err != nil {
fmt.Println(readRes.Error())
return
}
evalRes := mEval(readRes)
if evalRes.Err != nil {
fmt.Println(evalRes.Error())
return
}
printRes := mPrint(evalRes)
if printRes.Err != nil {
fmt.Println(printRes.Error())
}
}
func main() {
const PROMPT string = "user> "
for {
reader := bufio.NewReader(os.Stdin)
fmt.Print(PROMPT)
in, err := reader.ReadString('\n')
if err == io.EOF {
fmt.Println("\ngoodbye")
break
}
rep(in)
}
}