tisp

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

commit 7f332fcae06fb272248d3c6e156c2a1326c5509d
parent 54618f7fc9df7df77ff09dd62ddb8b1185b31581
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu,  7 Jan 2021 23:43:40 -0800

Add specialform and builtin type checkers

Diffstat:
tib/core.tsp | 46++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/tib/core.tsp b/tib/core.tsp @@ -45,28 +45,30 @@ ;;; Types -(def (any? x) True) -(def (void? x) (= (typeof x) "Void")) -(def (nil? x) (= (typeof x) "Nil")) -(def empty? nil?) -(def (integer? x) (= (typeof x) "Int")) ; TODO shorten type querry funcs ? -(def (decimal? x) (= (typeof x) "Dec")) -(def (ratio? x) (= (typeof x) "Ratio")) -(def (string? x) (= (typeof x) "Str")) -(def (symbol? x) (= (typeof x) "Sym")) -(def (primitive? x) (= (typeof x) "Prim")) -(def (function? x) (= (typeof x) "Func")) -(def (macro? x) (= (typeof x) "Macro")) -(def (pair? x) (= (typeof x) "Pair")) -(def (atom? x) (not (pair? x))) -(def (cons? x) (and (pair? x) (not (pair? (cdr x))))) -(def (list? x) (if (pair? x) (list? (cdr x)) (not x))) -(def (boolean? x) (or (= x True) (nil? x))) -(def (true? x) (= x True)) -(def false? nil?) -(def (procedure? x) (or (primitive? x) (or (function? x) (macro? x)))) -(def (rational? x) (or (integer? x) (ratio? x))) -(def (number? x) (or (rational? x) (decimal? x))) +(def (any? x) True) +(def (void? x) (= (typeof x) "Void")) +(def (nil? x) (= (typeof x) "Nil")) +(def empty? nil?) +(def (integer? x) (= (typeof x) "Int")) ; TODO shorten type querry funcs ? +(def (decimal? x) (= (typeof x) "Dec")) +(def (ratio? x) (= (typeof x) "Ratio")) +(def (string? x) (= (typeof x) "Str")) +(def (symbol? x) (= (typeof x) "Sym")) +(def (primitive? x) (= (typeof x) "Prim")) +(def (specialform? x) (= (typeof x) "Form")) +(def (function? x) (= (typeof x) "Func")) +(def (macro? x) (= (typeof x) "Macro")) +(def (pair? x) (= (typeof x) "Pair")) +(def (atom? x) (not (pair? x))) +(def (cons? x) (and (pair? x) (not (pair? (cdr x))))) +(def (list? x) (if (pair? x) (list? (cdr x)) (not x))) +(def (boolean? x) (or (= x True) (nil? x))) +(def (true? x) (= x True)) +(def false? nil?) +(def (builtin? x) (or (primitive? x) (specialform? x))) +(def (procedure? x) (or (builtin? x) (or (function? x) (macro? x)))) +(def (rational? x) (or (integer? x) (ratio? x))) +(def (number? x) (or (rational? x) (decimal? x))) (def (Bool x) (if x True Nil)) ; TODO handle string and sym