tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 635da0525dd864c33582b8ba469d0179c8475faf
parent f94e392c5611e7448b2baf5834a3a723f2401265
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sun,  9 Jun 2019 20:50:28 -0700

Simplify type function booleans

Diffstat:
tibs/lib.tsp | 46++++++++++++++--------------------------------
1 file changed, 14 insertions(+), 32 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -29,36 +29,18 @@ (define (cddddr x) (cdr (cdr (cdr (cdr x))))) ;;; Types -(define (void? x) - (cond ((= (type x) "void") t) - (t ()))) -(define (nil? x) - (cond ((= (type x) "nil") t) - (t ()))) -(define (integer? x) - (cond ((= (type x) "integer") t) - (t ()))) -(define (decimal? x) - (cond ((= (type x) "decimal") t) - (t ()))) -(define (ratio? x) - (cond ((= (type x) "ratio") t) - (t ()))) -(define (string? x) - (cond ((= (type x) "string") t) - (t ()))) -(define (symbol? x) - (cond ((= (type x) "symbol") t) - (t ()))) -(define (primitive? x) - (cond ((= (type x) "primitive") t) - (t ()))) -(define (function? x) - (cond ((= (type x) "function") t) - (t ()))) -(define (pair? x) - (cond ((= (type x) "pair") t) - (t ()))) +(define (void? x) (= (type x) "void")) +(define (nil? x) (= (type x) "nil")) +(define (integer? x) (= (type x) "integer")) +(define (decimal? x) (= (type x) "decimal")) +(define (ratio? x) (= (type x) "ratio")) +(define (string? x) (= (type x) "string")) +(define (symbol? x) (= (type x) "symbol")) +(define (primitive? x) (= (type x) "primitive")) +(define (function? x) (= (type x) "function")) +(define (pair? x) (= (type x) "pair")) +(define (rational? x) (or (integer? x) (ratio? x))) +(define (number? x) (or (rational? x) (decimal? x))) ;;; Control Flow (define if @@ -123,8 +105,8 @@ (define (max a b) (if (> a b) a b)) (define (min a b) (if (< a b) a b)) -(define (positive? x) (if (> x 0) t ())) -(define (negative? x) (if (< x 0) t ())) +(define (positive? x) (> x 0)) +(define (negative? x) (< x 0)) (define (! n) (if (= n 1)