/
bb.go
48 lines (37 loc) · 903 Bytes
/
bb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
fmt.Printf("Welcome the arogue repl! press ctrl-d to exit.\n")
scanner := bufio.NewScanner(os.Stdin)
lineNumber := 0
line := ""
var ok bool
ac := NewAccum() // accumulated source code, for type-checking
for {
// step one: read a line from the user on stdin
lineNumber++
fmt.Printf("%04d bb> ", lineNumber)
ok = scanner.Scan()
if !ok {
fmt.Printf("\nok was false. quitting.\n")
os.Exit(0)
}
if err := scanner.Err(); err != nil {
panic(err)
}
line = scanner.Text()
fmt.Printf("line is: '%s'\n", line)
// step two: translate from golang to scheme
schemeSrc, err := TranslateToScheme(line, ac)
if err != nil {
fmt.Printf("error on TranslateToScheme: '%v'\n", err)
continue
}
// step three: evaluate in the chicken-scheme repl
fmt.Printf("tranlation to R is: %#v\n", schemeSrc)
}
}