From bc3570ab3d91cc16109c1dea161e0a4cc94575ae Mon Sep 17 00:00:00 2001 From: ajet Date: Sun, 2 Nov 2025 03:48:53 -1000 Subject: [PATCH] init repl with string passthru --- eval/eval.go | 5 +++++ main.go | 42 ++++++++++++++++++++---------------------- print/print.go | 10 ++++++++++ read/read.go | 5 +++++ 4 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 eval/eval.go create mode 100644 print/print.go create mode 100644 read/read.go diff --git a/eval/eval.go b/eval/eval.go new file mode 100644 index 0000000..711505e --- /dev/null +++ b/eval/eval.go @@ -0,0 +1,5 @@ +package eval + +func Eval(ast any) any { + return ast +} diff --git a/main.go b/main.go index f69d26d..7adc9c5 100644 --- a/main.go +++ b/main.go @@ -1,31 +1,29 @@ package main import ( + "bufio" "fmt" - "mal-go/hash_map" - "mal-go/keyword" - "mal-go/list" - "mal-go/symbol" - "mal-go/vector" + "mal-go/eval" + "mal-go/print" + "mal-go/read" + "os" + "strings" ) func main() { - myList := list.New(5) - myList = myList.Conj(6) - plus := symbol.Intern("clojure.core", "+") - myList = myList.Conj(plus) - fmt.Println(myList) + //repl + fmt.Println("mal-go pre-alpha") + reader := bufio.NewReader(os.Stdin) + for true { + fmt.Print("user=>") + input, _ := reader.ReadString('\n') + input = strings.TrimSpace(input) - baz := keyword.Intern("baz") - myMap := hash_map.New() - myMap = myMap.Conj("foo", "bar") - myMap = myMap.Conj(baz, 42) - myMap = myMap.Conj("fizz", "buzz") - fmt.Println(myMap) - - myVec := vector.New() - myVec = myVec.Conj(plus) - myVec = myVec.Conj(1) - myVec = myVec.Conj(2) - fmt.Println(myVec) + if strings.Compare(input, "exit") == 0 { + return + } + ast := read.ReadString(input) + result := eval.Eval(ast) + print.Print(result) + } } diff --git a/print/print.go b/print/print.go new file mode 100644 index 0000000..56ad9a4 --- /dev/null +++ b/print/print.go @@ -0,0 +1,10 @@ +package print + +import ( + "fmt" + "mal-go/utils" +) + +func Print(ast any) { + fmt.Println(utils.Stringify(ast)) +} diff --git a/read/read.go b/read/read.go new file mode 100644 index 0000000..a43acbc --- /dev/null +++ b/read/read.go @@ -0,0 +1,5 @@ +package read + +func ReadString(s string) any { + return s +}