diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-04 18:34:26 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-10-04 18:34:26 -0500 |
| commit | 69b4abd6efc7c65e59f73158ca93f4aa9b73116d (patch) | |
| tree | 5ca4e17a98bd9c82618db2981c779e8097d7a17e | |
| parent | 3b655472663583c58a6a6e113fb6cc5384ad7e50 (diff) | |
| download | mal-69b4abd6efc7c65e59f73158ca93f4aa9b73116d.tar.gz mal-69b4abd6efc7c65e59f73158ca93f4aa9b73116d.zip | |
go: step0_repl
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | go/Makefile | 31 | ||||
| -rw-r--r-- | go/step0_repl.go | 41 |
3 files changed, 75 insertions, 1 deletions
@@ -10,7 +10,7 @@ PYTHON = python # Settings # -IMPLS = bash c clojure cs java js make mal perl php ps python ruby +IMPLS = bash c clojure cs go java js make mal perl php ps python ruby step0 = step0_repl step1 = step1_read_print @@ -49,6 +49,7 @@ bash_STEP_TO_PROG = bash/$($(1)).sh c_STEP_TO_PROG = c/$($(1)) clojure_STEP_TO_PROG = clojure/src/$($(1)).clj cs_STEP_TO_PROG = cs/$($(1)).exe +go_STEP_TO_PROG = go/$($(1)) java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java js_STEP_TO_PROG = js/$($(1)).js make_STEP_TO_PROG = make/$($(1)).mk @@ -64,6 +65,7 @@ bash_RUNSTEP = bash ../$(2) $(3) c_RUNSTEP = ../$(2) $(3) clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3) cs_RUNSTEP = mono ../$(2) --raw $(3) +go_RUNSTEP = ../$(2) $(3) java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" -Dexec.args="--raw$(if $(3), $(3),)" js_RUNSTEP = node ../$(2) $(3) make_RUNSTEP = make -f ../$(2) $(3) 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)) + } +} |
