init repl with string passthru

This commit is contained in:
Adam Jeniski 2025-11-02 03:48:53 -10:00
parent 143b17a6c1
commit bc3570ab3d
4 changed files with 40 additions and 22 deletions

5
eval/eval.go Normal file
View File

@ -0,0 +1,5 @@
package eval
func Eval(ast any) any {
return ast
}

42
main.go
View File

@ -1,31 +1,29 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"mal-go/hash_map" "mal-go/eval"
"mal-go/keyword" "mal-go/print"
"mal-go/list" "mal-go/read"
"mal-go/symbol" "os"
"mal-go/vector" "strings"
) )
func main() { func main() {
myList := list.New(5) //repl
myList = myList.Conj(6) fmt.Println("mal-go pre-alpha")
plus := symbol.Intern("clojure.core", "+") reader := bufio.NewReader(os.Stdin)
myList = myList.Conj(plus) for true {
fmt.Println(myList) fmt.Print("user=>")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
baz := keyword.Intern("baz") if strings.Compare(input, "exit") == 0 {
myMap := hash_map.New() return
myMap = myMap.Conj("foo", "bar") }
myMap = myMap.Conj(baz, 42) ast := read.ReadString(input)
myMap = myMap.Conj("fizz", "buzz") result := eval.Eval(ast)
fmt.Println(myMap) print.Print(result)
}
myVec := vector.New()
myVec = myVec.Conj(plus)
myVec = myVec.Conj(1)
myVec = myVec.Conj(2)
fmt.Println(myVec)
} }

10
print/print.go Normal file
View File

@ -0,0 +1,10 @@
package print
import (
"fmt"
"mal-go/utils"
)
func Print(ast any) {
fmt.Println(utils.Stringify(ast))
}

5
read/read.go Normal file
View File

@ -0,0 +1,5 @@
package read
func ReadString(s string) any {
return s
}