Permalink
Browse files

Add EVEN? and ODD?.

  • Loading branch information...
1 parent 7808e4f commit 5c23cd8a4394ba73b588572da9e3852961753af5 @manuel committed Mar 21, 2012
Showing with 16 additions and 0 deletions.
  1. +6 −0 standard.virtua
  2. +10 −0 test.virtua
View
@@ -201,6 +201,9 @@
(eval (list* (setter (eval cmb env)) value args) env))
(eval (list $set! place value) env)))
+(defmacro op! (place op) env
+ (eval (list set! place (list op place)) env))
+
(defmacro fluid-let ((name value) . body) env
(let ((saved-value (eval name env)))
(eval (list set! name value) env)
@@ -510,6 +513,9 @@
(defmacro dec! (var . delta) env
(eval (list set! var (list - var (if (pair? delta) (car delta) 1))) env))
+(defun even? ((n Number)) (= 0 (% n 2)))
+(defun odd? ((n Number)) (not? (even? n)))
+
;;;; Comparison
(def number< (js-binop "<"))
View
@@ -71,6 +71,16 @@
(assert (eq? #ignore #ignore))
(assert (eq? #void #void))
+;;;; Numbers
+
+(assert (even? 0))
+(assert (even? -100))
+(assert (even? 100))
+(assert (not? (even? 3)))
+(assert (not? (even? -3)))
+(assert (odd? 101))
+(assert (odd? -101))
+
;;;; Object System
(assert (instance? Object Class))

0 comments on commit 5c23cd8

Please sign in to comment.