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
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)
}
}

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
}