diff options
Diffstat (limited to 'go')
| -rw-r--r-- | go/Makefile | 31 | ||||
| -rw-r--r-- | go/step0_repl.go | 41 |
2 files changed, 72 insertions, 0 deletions
diff --git a/go/Makefile b/go/Makefile new file mode 100644 index 0000000..85719bf --- /dev/null +++ b/go/Makefile @@ -0,0 +1,31 @@ +##################### + +SOURCES_BASE = +SOURCES_LISP = step0_repl.go +SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) + + +##################### + +SRCS = step0_repl.go +BINS = $(SRCS:%.go=%) + +##################### + +all: $(BINS) mal + +mal: $(word $(words $(BINS)),$(BINS)) + cp $< $@ + +$(BINS): %: %.go + go build -o $@ $+ + +clean: + rm -f $(BINS) mal + +.PHONY: stats stats-lisp + +stats: $(SOURCES) + @wc $^ +stats-lisp: $(SOURCES_LISP) + @wc $^ diff --git a/go/step0_repl.go b/go/step0_repl.go new file mode 100644 index 0000000..6e559c9 --- /dev/null +++ b/go/step0_repl.go @@ -0,0 +1,41 @@ +package main + +import ( + "bufio" + //"io" + "fmt" + "os" +) + +// read +func READ(str string) string { + return str +} + +// eval +func EVAL(ast string, env string) string { + return ast +} + +// print +func PRINT(exp string) string { + return exp +} + +// repl +func rep(str string) string { + return PRINT(EVAL(READ(str), "")) +} + +func main() { + reader := bufio.NewReader(os.Stdin); + // repl loop + for { + fmt.Print("user> "); + text, err := reader.ReadString('\n'); + if (err != nil) { + return + } + fmt.Println(rep(text)) + } +} |
