Commits

Anonymous committed 7d4743d

gofix for new form of error()

  • Participants
  • Parent commits 8605930

Comments (0)

Files changed (2)

File file_test.go

 
 func TestForth(t *testing.T) {
 
-	forthTests[0].res,_ = os.Hostname()
+	forthTests[0].res, _ = os.Hostname()
 	f := New()
 	if f.Length() != 0 {
 		t.Errorf("Test: stack is %d and should be 0", f.Length())
 		t.Errorf("Test: After Reset(): stack is %v and should be true", f.Empty())
 	}
 	for _, tt := range forthTests {
-		var err os.Error
+		var err error
 		res, err := Eval(f, tt.val)
-		if res == tt.res || (err != nil && err.String() == tt.err) {
+		if res == tt.res || (err != nil && err.Error() == tt.err) {
 			fmt.Printf("Test: '%v' '%v' '%v': Pass\n", tt.val, res, err)
 		} else {
 			t.Errorf("Test: '%v' '%v' '%v': Fail\n", tt.val, res, err)
 			t.Errorf("Test: %v: stack is %v and should be empty", tt, f.Empty())
 		}
 	}
-	
+
 }
 package forth
 
 import (
-	"strconv"
+	"errors"
 	"os"
 	"runtime"
+	"strconv"
 	"strings"
 )
 
-type forthop func (f Forth)
+type forthop func(f Forth)
 
 type forthstack struct {
 	stack []string
 }
 
-var opmap = map[string] forthop {
-	"+": plus, 
-	"-": sub, 
-	"*": times, 
-	"/": div, 
-	"%": mod, 
-	"swap": swap,
-	"ifelse": ifelse,
+var opmap = map[string]forthop{
+	"+":        plus,
+	"-":        sub,
+	"*":        times,
+	"/":        div,
+	"%":        mod,
+	"swap":     swap,
+	"ifelse":   ifelse,
 	"hostname": hostname,
 	"hostbase": hostbase,
-	"strcat": strcat,
-	"roundup": roundup,
-	"dup": dup,
+	"strcat":   strcat,
+	"roundup":  roundup,
+	"dup":      dup,
 }
 
 // Forth is an interface used by the package. The interface
 // requires definition of Push, Pop, Length, Empty (convenience function
 // meaning Length is 0), Newop (insert a new or replacement operator), 
 // and Reset (clear the stack, mainly diagnostic)
-type Forth  interface{
+type Forth interface {
 	Push(string)
-	Pop() (string)
+	Pop() string
 	Length() int
 	Empty() bool
 	Newop(string, forthop)
 
 // Pop pops the stack. If the stack is Empty Pop will panic. 
 // Eval recovers() the panic. 
-func (f *forthstack) Pop() (ret string){
+func (f *forthstack) Pop() (ret string) {
 
 	if len(f.stack) < 1 {
-		panic(os.NewError("Empty stack"))
+		panic(errors.New("Empty stack"))
 	}
 	ret = f.stack[len(f.stack)-1]
-	f.stack = f.stack[0:len(f.stack)-1]
+	f.stack = f.stack[0 : len(f.stack)-1]
 	//fmt.Printf("Pop: %v stack %v\n", ret, f.stack)
 	return ret
 }
 func (f *forthstack) Empty() bool {
 	return len(f.stack) == 0
 }
-	
+
 // errRecover converts panics to errstr iff it is an os.Error, panics
 // otherwise. 
-func errRecover(errp *os.Error){
+func errRecover(errp *error) {
 	e := recover()
 	if e != nil {
 		if _, ok := e.(runtime.Error); ok {
 			panic(e)
 		}
-		*errp = e.(os.Error)
+		*errp = e.(error)
 	}
 }
 
  * operator if it is found in the opmap. It returns TOS when it is done. 
  * it is an error to leave the stack non-Empty. 
  */
-func Eval(f Forth, s string) (ret string, err os.Error) {
+func Eval(f Forth, s string) (ret string, err error) {
 	defer errRecover(&err)
-	for _, val := range(strings.Split(s, " ")) {
+	for _, val := range strings.Split(s, " ") {
 		/* two or more spaces can have odd results */
 		if len(val) == 0 || val == " " {
 			continue
 	}
 	ret = f.Pop()
 	return
-	
+
 }
 
 func plus(f Forth) {
 func sub(f Forth) {
 	x, _ := strconv.Atoi(f.Pop())
 	y, _ := strconv.Atoi(f.Pop())
-	z := y-x
+	z := y - x
 	f.Push(strconv.Itoa(z))
 }
 
 func div(f Forth) {
 	x, _ := strconv.Atoi(f.Pop())
 	y, _ := strconv.Atoi(f.Pop())
-	z := y/x
+	z := y / x
 	f.Push(strconv.Itoa(z))
 }
 
 func mod(f Forth) {
 	x, _ := strconv.Atoi(f.Pop())
 	y, _ := strconv.Atoi(f.Pop())
-	z := y%x
+	z := y % x
 	f.Push(strconv.Itoa(z))
 }
 
 func roundup(f Forth) {
 	rnd, _ := strconv.Atoi(f.Pop())
 	v, _ := strconv.Atoi(f.Pop())
-	v = ((v + rnd-1)/rnd)*rnd
+	v = ((v + rnd - 1) / rnd) * rnd
 	f.Push(strconv.Itoa(v))
 }
 
 func strcat(f Forth) {
 	x := f.Pop()
 	y := f.Pop()
-	f.Push(y+x)
+	f.Push(y + x)
 }
 
 func dup(f Forth) {
 }
 
 func ifelse(f Forth) {
-	x,_ := strconv.Atoi(f.Pop())
+	x, _ := strconv.Atoi(f.Pop())
 	y := f.Pop()
 	z := f.Pop()
 	if x != 0 {
 	}
 }
 
-func hostname(f Forth){
+func hostname(f Forth) {
 	h, err := os.Hostname()
 	if err != nil {
 		panic("No hostname")