Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fully working error handling in REPL

  • Loading branch information...
commit 6b238113b1bb36f9137edd2a815bd3f5db6c81dd 1 parent 9af9f3e
Scott Lawrence authored
Showing with 22 additions and 1 deletion.
  1. +18 −0 lisp/builtins.go
  2. +4 −1 repl.lsp
18 lisp/builtins.go
View
@@ -35,6 +35,9 @@ func init() {
"car": function(builtinCar),
"cdr": function(builtinCdr),
+ // Basic stuff
+ "equal?": function(builtinEqual),
+
// Boolean arithmetic (bool.go)
"not": function(builtinNot),
@@ -109,3 +112,18 @@ func builtinApply(sc *scope, ss []sexpr) sexpr {
}
return apply(sc, ss[0], flatten(ss[1]))
}
+
+// (equal? arg1 ...)
+func builtinEqual(sc *scope, ss []sexpr) sexpr {
+ if len(ss) == 0 {
+ return 1.0
+ }
+ r := true
+ for _, s := range ss[1:] {
+ r = r && (s == ss[0])
+ }
+ if r {
+ return 1.0
+ }
+ return Nil
+}
5 repl.lsp
View
@@ -19,7 +19,10 @@
(for 1
(recover '(_)
(lambda () (print (eval (readSexpr))))
- (lambda (e) (fmt.Println e)))))
+ (lambda (e)
+ (if (equal? e 'eof)
+ (panic e)
+ (fmt.Println e))))))
(lambda (_)
(fmt.Println "Bye!")))))))
(REPL)
Please sign in to comment.
Something went wrong with that request. Please try again.