Skip to content

Commit a3c7023

Browse files
author
Jeff Aigner
committed
Running gofmt on code, adding gitignore to drop binary name
1 parent 4340c21 commit a3c7023

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
golisp

lisp.go

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package main
22

33
import (
4-
"fmt"
54
"bufio"
5+
"fmt"
66
"os"
7-
"strings"
87
"strconv"
8+
"strings"
99
)
1010

1111
func removeEmpty(tokens []string) []string {
@@ -25,13 +25,13 @@ func parse(program string) Object {
2525

2626
type Env struct {
2727
mapping map[Symbol]Object
28-
outer *Env
28+
outer *Env
2929
}
3030

3131
type Procedure struct {
3232
body Object
3333
args []Object
34-
env Env
34+
env Env
3535
}
3636

3737
type Object interface{}
@@ -92,39 +92,39 @@ func mult(a, b Object) Object {
9292

9393
func add(a, b Object) Object {
9494
x, y := a.(Number), b.(Number)
95-
return x + y
95+
return x + y
9696
}
9797

9898
func sub(a, b Object) Object {
9999
x, y := a.(Number), b.(Number)
100-
return x - y
100+
return x - y
101101
}
102102

103103
func gt(a, b Object) Object {
104104
x, y := a.(Number), b.(Number)
105-
return x > y
105+
return x > y
106106
}
107107

108108
func getStandardEnv() Env {
109109
e := Env{
110110
mapping: make(map[Symbol]Object),
111111
}
112112
e.mapping["*"] = mult
113-
e.mapping["+"] = add
114-
e.mapping["-"] = sub
115-
e.mapping[">"] = gt
113+
e.mapping["+"] = add
114+
e.mapping["-"] = sub
115+
e.mapping[">"] = gt
116116
e.mapping["pi"] = Number(3.141592654)
117117
return e
118118
}
119119

120120
func (e *Env) eval(x Object) Object {
121121
if val, is_symbol := x.(Symbol); is_symbol {
122-
return e.mapping[val]
122+
return e.mapping[val]
123123
} else if _, is_list := x.(List); !is_list {
124-
return x
124+
return x
125125
} else if l := x.(List); l[0] == Symbol("define") {
126126
val := e.eval(l[2])
127-
e.mapping[ l[1].(Symbol) ] = val
127+
e.mapping[l[1].(Symbol)] = val
128128
return val
129129
} else if l := x.(List); l[0] == Symbol("if") {
130130
truth := e.eval(l[1]).(bool)
@@ -139,7 +139,7 @@ func (e *Env) eval(x Object) Object {
139139
proc := e.eval(l[0])
140140
a1 := e.eval(l[1])
141141
a2 := e.eval(l[2])
142-
res := proc.(func(Object,Object)Object)(a1, a2)
142+
res := proc.(func(Object, Object) Object)(a1, a2)
143143
return res
144144
}
145145
}
@@ -158,4 +158,3 @@ func main() {
158158

159159
repl(e)
160160
}
161-

lisp_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import "testing"
44

55
func TestEval(t *testing.T) {
66
cases := []struct {
7-
in string
8-
want Object
7+
in string
8+
want Object
99
}{
1010
{"(define x 10)", Number(10)},
1111
{"(define r 10.3)", Number(10.3)},

0 commit comments

Comments
 (0)