tisp

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

commit 2d9cdf1a060d75ab8a439a15489ba7d2735630d9
parent 6d7c89f476fe0d270c7b59934b000da53ee57d55
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri,  2 Oct 2020 20:35:27 -0700

Captialize type names

Diffstat:
test.c | 192++++++++++++++++++++++++++++++++++++++++----------------------------------------
tib/core.tsp | 61+++++++++++++++++++++++++++++++++----------------------------
tib/io.tsp | 4++--
tib/math.c | 16++++++++--------
tib/math.tsp | 6++++--
tib/repl.tsp | 4++--
tib/string.c | 13++++++-------
tisp.c | 38+++++++++++++++++++-------------------
8 files changed, 170 insertions(+), 164 deletions(-)

diff --git a/test.c b/test.c @@ -55,9 +55,9 @@ char *tests[][2] = { { "-6/-3", "2" }, { "\"foo\"", "foo" }, { "\"foo bar\"", "foo bar" }, - { "t", "t" }, - { "()", "nil" }, - { "nil", "nil" }, + { "True", "True" }, + { "()", "Nil" }, + { "Nil", "Nil" }, { "comments", NULL }, { "; commment", "#<void>" }, @@ -119,8 +119,8 @@ char *tests[][2] = { { "cond", NULL }, { "(cond)", "#<void>" }, - { "(cond (t 1))", "1" }, - { "(cond ((= 1 1) 1) ((= 1 2) 2) (t 3))", "1" }, + { "(cond (True 1))", "1" }, + { "(cond ((= 1 1) 1) ((= 1 2) 2) (True 3))", "1" }, { "(cond ((= 1 2) 1) ((= 1 2) 2) (else (+ 1 2)))", "3" }, { "(cond ((= 1 2) 1) ((= 1 1) 2) (else 3))", "2" }, { "(cond ((= 1 2) 1) ((= 1 3) 2))", "#<void>" }, @@ -141,43 +141,43 @@ char *tests[][2] = { { "(get 10/15 'den)", "3" }, { "(get 9/2 'num)", "9" }, - { "eq", NULL }, - { "(=)", "t" }, - { "(= 1)", "t" }, - { "(= \"foo\")", "t" }, - { "(= 1 1)", "t" }, - { "(= 1 1 1 1 1 1)", "t" }, - { "(= 1 2)", "nil" }, - { "(= 1 1 2 1 1 1)", "nil" }, - { "(= 1 1 1 1 1 2)", "nil" }, - { "(= 2 1 1 1 1 1)", "nil" }, - { "(= 4/5 4/5)", "t" }, - { "(= 2/1 2)", "t" }, - { "(= 2/4 1/2)", "t" }, - { "(= 2/4 1/2 4/8 3/6)", "t" }, - { "(= 1/2 4/5)", "nil" }, - { "(= 5/4 4/5)", "nil" }, - { "(= 3 3/2)", "nil" }, - { "(= 3 3/2 3 3 3)", "nil" }, - { "(= (+ 1 1) (+ 2 0))", "t" }, - { "(= \"foo\" \"foo\")", "t" }, - { "(= \"foo\" \"bar\")", "nil" }, - { "(= \"foo\" \"foo\" \"foo\" \"foo\" \"foo\")", "t" }, - { "(= \"foo\" \"bar\" \"foo\" \"foo\" \"foo\")", "nil" }, - { "(= \"foo\" 3)", "nil" }, - { "(= \"foo\" \"foo\" 4 \"foo\" \"foo\")", "nil" }, - { "(= \"foo\" \"FOO\")", "nil" }, - { "(= t t)", "t" }, - { "(= car car)", "t" }, - { "(= car cdr)", "nil" }, - { "(= quote quote quote)", "t" }, - { "(= '(1 2 3) '(1 2 3))", "t" }, - { "(= '(a b c) '(a b c))", "t" }, - { "(= '(a b c) '(a b d))", "nil" }, - { "(= '(1 2 3) '(1 2))", "nil" }, - { "(= '(1 2 3) '(1))", "nil" }, - { "(= '((1 2) 3 4) '((1 2) 3 4))", "t" }, - { "(= '((1 b) 3 4) '((1 2) 3 4))", "nil" }, + { "eq", NULL }, + { "(=)", "True" }, + { "(= 1)", "True" }, + { "(= \"foo\")", "True" }, + { "(= 1 1)", "True" }, + { "(= 1 1 1 1 1 1)", "True" }, + { "(= 1 2)", "Nil" }, + { "(= 1 1 2 1 1 1)", "Nil" }, + { "(= 1 1 1 1 1 2)", "Nil" }, + { "(= 2 1 1 1 1 1)", "Nil" }, + { "(= 4/5 4/5)", "True" }, + { "(= 2/1 2)", "True" }, + { "(= 2/4 1/2)", "True" }, + { "(= 2/4 1/2 4/8 3/6)", "True" }, + { "(= 1/2 4/5)", "Nil" }, + { "(= 5/4 4/5)", "Nil" }, + { "(= 3 3/2)", "Nil" }, + { "(= 3 3/2 3 3 3)", "Nil" }, + { "(= (+ 1 1) (+ 2 0))", "True" }, + { "(= \"foo\" \"foo\")", "True" }, + { "(= \"foo\" \"bar\")", "Nil" }, + { "(= \"foo\" \"foo\" \"foo\" \"foo\" \"foo\")", "True" }, + { "(= \"foo\" \"bar\" \"foo\" \"foo\" \"foo\")", "Nil" }, + { "(= \"foo\" 3)", "Nil" }, + { "(= \"foo\" \"foo\" 4 \"foo\" \"foo\")", "Nil" }, + { "(= \"foo\" \"FOO\")", "Nil" }, + { "(= True True)", "True" }, + { "(= car car)", "True" }, + { "(= car cdr)", "Nil" }, + { "(= quote quote quote)", "True" }, + { "(= '(1 2 3) '(1 2 3))", "True" }, + { "(= '(a b c) '(a b c))", "True" }, + { "(= '(a b c) '(a b d))", "Nil" }, + { "(= '(1 2 3) '(1 2))", "Nil" }, + { "(= '(1 2 3) '(1))", "Nil" }, + { "(= '((1 2) 3 4) '((1 2) 3 4))", "True" }, + { "(= '((1 b) 3 4) '((1 2) 3 4))", "Nil" }, { "def", NULL }, { "(def foo 4)", "#<void>" }, @@ -212,14 +212,14 @@ char *tests[][2] = { { "((lambda () 5))", "5" }, { "control", NULL }, - { "(if t 1 2)", "1" }, + { "(if True 1 2)", "1" }, { "(if () 1 2)", "2" }, - { "(if (integer? 3) t ())", "t" }, + { "(if (integer? 3) True ())", "True" }, { "(if (ratio? car) (cons 1 2) (car '(1 2)))", "1" }, - { "(when t 'foo)", "foo" }, + { "(when True 'foo)", "foo" }, { "(when () 'b ar)", "#<void>" }, { "(when (= 1 1) 4)", "4" }, - { "(unless t 'foo)", "#<void>" }, + { "(unless True 'foo)", "#<void>" }, { "(unless () 'bar)", "bar" }, { "(unless 3 4)", "#<void>" }, { "(unless (< 5 4) 7)", "7" }, @@ -228,32 +228,32 @@ char *tests[][2] = { { "(switch 2 (3 'yes) (5 'no))", "#<void>" }, { "(switch \"foo\" (e \"bar\") (\"foo\" 'zar) ('baz 3))", "zar" }, - { "logic", NULL }, - { "(not ())", "t" }, - { "(not t)", "nil" }, - { "(and () ())", "nil" }, - { "(and t ())", "nil" }, - { "(and () t)", "nil" }, - { "(and t t)", "t" }, - { "(nand () ())", "t" }, - { "(nand t ())", "t" }, - { "(nand () t)", "t" }, - { "(nand t t)", "nil" }, - { "(or () ())", "nil" }, - { "(or t ())", "t" }, - { "(or () t)", "t" }, - { "(or t t)", "t" }, - { "(nor () ())", "t" }, - { "(nor t ())", "nil" }, - { "(nor () t)", "nil" }, - { "(nor t t)", "nil" }, + { "logic", NULL }, + { "(not ())", "True" }, + { "(not True)", "Nil" }, + { "(and () ())", "Nil" }, + { "(and True ())", "Nil" }, + { "(and () True)", "Nil" }, + { "(and True True)", "True" }, + { "(nand () ())", "True" }, + { "(nand True ())", "True" }, + { "(nand () True)", "True" }, + { "(nand True True)", "Nil" }, + { "(or () ())", "Nil" }, + { "(or True ())", "True" }, + { "(or () True)", "True" }, + { "(or True True)", "True" }, + { "(nor () ())", "True" }, + { "(nor True ())", "Nil" }, + { "(nor () True)", "Nil" }, + { "(nor True True)", "Nil" }, { "list", NULL }, { "(list 1 2 3)", "(1 2 3)" }, { "(list (* 2 2) (+ 2 3))", "(4 5)" }, { "(list 'a 'b 'c 'd 'e 'f)", "(a b c d e f)" }, { "(list \"foo\")", "(foo)" }, - { "(list)", "nil" }, + { "(list)", "Nil" }, { "(list 1/2 2/8 . 1/8)", "(1/2 1/4 . 1/8)" }, { "(list* .5 .25 .125)", "(0.5 0.25 . 0.125)" }, { "(list* 1 2 3 4 5 6)", "(1 2 3 4 5 . 6)" }, @@ -270,7 +270,7 @@ char *tests[][2] = { { "(length '(a b))", "2" }, { "(length (list list))", "1" }, { "(length ())", "0" }, - { "(length nil)", "0" }, + { "(length Nil)", "0" }, { "(nth '(1 2 3) 1)", "2" }, { "(nth (list 3 5/2 .332 -2) 2)", "0.332" }, { "(nth '(a b c) 0)", "a" }, @@ -278,14 +278,14 @@ char *tests[][2] = { { "(head '(1.2 1.3 1.4 1.5) 2)", "(1.2 1.3)" }, { "(head '(1 1e1 1e2 1e3) 3)", "(1 10 100)" }, { "(head '(1 2 3) 1)", "(1)" }, - { "(head '(1 2) 0)", "nil" }, + { "(head '(1 2) 0)", "Nil" }, { "(tail '(randy bobandy lahey bubs) 3)", "(bubs)" }, { "(tail (list 1/2 1/3 1/4) 0)", "(1/2 1/3 1/4)" }, { "(tail '(2 4 9 16 25 36) 2)", "(9 16 25 36)" }, { "(count 3 '(1 2 3 4))", "1" }, { "(count 1/2 (list 1/2 1/3 2/4 8 9.0))", "2" }, { "(count 'a '(b c a a f h a b c a))", "4" }, - { "(count 3.2 nil)", "0" }, + { "(count 3.2 Nil)", "0" }, { "(count \"Bobandy\" '(1/2 1/4 \"Jim\"))", "0" }, { "list proc", NULL }, @@ -305,7 +305,7 @@ char *tests[][2] = { { "((compose - sqrt cube) 4)", "-8" }, { "((compose -) 5/3)", "-5/3" }, { "((compose - +) 5 6)", "-11" }, - { "((compose sqrt integer *) 4.5 2)", "3" }, + { "((compose sqrt Int *) 4.5 2)", "3" }, /* { "(foldr + 0 '(1 2 4 5))", "12" }, */ /* { "(foldr list 0 '(1 2 3 4))", "((((0 1) 2) 3) 4)" }, */ @@ -314,8 +314,8 @@ char *tests[][2] = { { "(reverse (list -20 5/2 .398))", "(0.398 5/2 -20)" }, { "(reverse '(a b))", "(b a)" }, { "(reverse (list \"foo\" \"bar\" \"baz\"))", "(baz bar foo)" }, - { "(reverse (cons 1/2 nil))", "(1/2)" }, - { "(reverse ())", "nil" }, + { "(reverse (cons 1/2 Nil))", "(1/2)" }, + { "(reverse ())", "Nil" }, { "(append '(1 2 3) '(4 5 6))", "(1 2 3 4 5 6)" }, { "(append (list (+ 1 2) 4) '(a b c))", "(3 4 a b c)" }, @@ -326,7 +326,7 @@ char *tests[][2] = { "((ricky . julian) (lahey . randy))" }, { "(assoc 'baz '((foo . 3) (bar . 8) (baz . 14)))", "(baz . 14)" }, { "(assoc 'a '((a b) (3 2.1) (3.2 4/3) (3.2 3.2)))", "(a b)" }, - { "(assoc 3 '((1 b)))", "nil" }, + { "(assoc 3 '((1 b)))", "Nil" }, { "(assoc 4/3 (list (list 1 pi) (list 4/3 1/2 3) (list 2 3)))", "(4/3 1/2 3)" }, { "member", NULL }, @@ -339,8 +339,8 @@ char *tests[][2] = { { "(member 'bar '(foo bar baz))", "(bar baz)" }, { "(member 4 '(12 38 4 8))", "(4 8)" }, { "(member 3.2 '(4/3 2 8 2 3.14 3.2))", "(3.2)" }, - { "(member \"quux\" (list 4.2 3 'quux))", "nil" }, - { "(member 'qux '(foo bar baz))", "nil" }, + { "(member \"quux\" (list 4.2 3 'quux))", "Nil" }, + { "(member 'qux '(foo bar baz))", "Nil" }, { "quasiquote", NULL }, { "`7.2", "7.2" }, @@ -383,14 +383,14 @@ char *tests[][2] = { { "s", "(-1/2 3/2 3 4 5)" }, { "numbers", NULL }, - { "(decimal 1/2)", "0.5" }, - { "(decimal 3/-2)", "-1.5" }, - { "(decimal 1)", "1.0" }, - { "(decimal 3.14)", "3.14" }, - { "(integer 1/2)", "0" }, - { "(integer 3/-2)", "-1" }, - { "(integer 1)", "1" }, - { "(integer 3.14)", "3" }, + { "(Dec 1/2)", "0.5" }, + { "(Dec 3/-2)", "-1.5" }, + { "(Dec 1)", "1.0" }, + { "(Dec 3.14)", "3.14" }, + { "(Int 1/2)", "0" }, + { "(Int 3/-2)", "-1" }, + { "(Int 1)", "1" }, + { "(Int 3.14)", "3" }, { "(numerator 3/2)", "3" }, { "(numerator 1/2)", "1" }, { "(numerator -4/2)", "-2" }, @@ -488,19 +488,19 @@ char *tests[][2] = { { "(mod 7 2)", "1" }, { "(mod 8 5)", "3" }, - { "compare", NULL }, - { "(< 2 3)", "t" }, - { "(< 3 3)", "nil" }, - { "(< 4 3)", "nil" }, - { "(<= -2 +4)", "t" }, - { "(<= -2 -2)", "t" }, - { "(<= 4 -2)", "nil" }, - { "(> 89 34)", "t" }, - { "(> 48 48)", "nil" }, - { "(> 98 183)", "nil" }, - { "(>= +4 -282)", "t" }, - { "(>= 39 39)", "t" }, - { "(>= -32 -30)", "nil" }, + { "compare", NULL }, + { "(< 2 3)", "True" }, + { "(< 3 3)", "Nil" }, + { "(< 4 3)", "Nil" }, + { "(<= -2 +4)", "True" }, + { "(<= -2 -2)", "True" }, + { "(<= 4 -2)", "Nil" }, + { "(> 89 34)", "True" }, + { "(> 48 48)", "Nil" }, + { "(> 98 183)", "Nil" }, + { "(>= +4 -282)", "True" }, + { "(>= 39 39)", "True" }, + { "(>= -32 -30)", "Nil" }, { "abs", NULL }, { "(abs 4)", "4" }, diff --git a/tib/core.tsp b/tib/core.tsp @@ -5,6 +5,7 @@ (list 'def (car args) (list 'macro (cdr args) . body)))) ;;; CXR + (def (caar x) (car (car x))) (def (cadr x) (car (cdr x))) (def (cdar x) (cdr (car x))) @@ -35,30 +36,31 @@ (def (cddddr x) (cdr (cdr (cdr (cdr x))))) ;;; Types -(def (any? x) t) -(def (void? x) (= (typeof x) "void")) -(def (nil? x) (= (typeof x) "nil")) + +(def (any? x) True) +(def (void? x) (= (typeof x) "Void")) +(def (nil? x) (= (typeof x) "Nil")) (def empty? nil?) -(def (integer? x) (= (typeof x) "integer")) -(def (decimal? x) (= (typeof x) "decimal")) -(def (ratio? x) (= (typeof x) "ratio")) -(def (string? x) (= (typeof x) "string")) -(def (symbol? x) (= (typeof x) "symbol")) -(def (primitive? x) (= (typeof x) "primitive")) -(def (function? x) (= (typeof x) "function")) -(def (macro? x) (= (typeof x) "macro")) -(def (pair? x) (= (typeof x) "pair")) +(def (integer? x) (= (typeof x) "Int")) +(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 t) (nil? x))) -(def (true? x) (= x t)) +(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 (bool x) (if x t nil)) +(def (bool x) (if x True Nil)) ; TODO handle string and sym (def (pair x) (cond @@ -84,10 +86,11 @@ (else (error 'default "expected only 1 optional argument")))) ;;; Control Flow + ; TODO if b = pair and car b = else use cdr b (defmacro (if con a b) - (list 'cond (list con a) (list t b))) -(def else t) + (list 'cond (list con a) (list True b))) +(def else True) (defmacro (when con . body) (list 'cond (list con (cons 'do body)))) (defmacro (unless con . body) @@ -143,14 +146,14 @@ (defmacro (unquote x) (list error ''unquote "called outside of quasiquote")) ;;; Logic -(def true t) -(def false ()) + +(def False ()) (def (not x) - (if x nil t)) + (if x Nil True)) ; TODO logic func many arguments ; Use a macro so arguments aren't evaluated all at once (defmacro (and a b) - (list 'if a b nil)) + (list 'if a b Nil)) (defmacro (nand a b) (list 'not (list 'and a b))) (defmacro (or a b) @@ -159,6 +162,7 @@ (list 'not (list 'or a b))) ;;; Lists + (def (list* . lst) (if (cdr lst) (cons (car lst) (apply list* (cdr lst))) @@ -191,7 +195,7 @@ ; TODO support negative numers like unix tail/head to count from end backwards (def (head lst n) (cond - ((<= n 0) nil) + ((<= n 0) Nil) ((atom? lst) (error 'name "index of list out of bounds")) (else (cons (car lst) (head (cdr lst) (- n 1)))))) @@ -220,11 +224,11 @@ (if lst (cons (proc (car lst)) (map proc (cdr lst))) - nil)) + Nil)) (def (filter proc lst) (cond - ((not (pair? lst)) nil) + ((not (pair? lst)) Nil) ((proc (car lst)) (cons (car lst) (filter proc (cdr lst)))) (else (filter proc (cdr lst))))) @@ -237,7 +241,7 @@ ((car procs) (apply (apply compose (cdr procs)) x)))))) (def (reverse l) - (recur f ((in l) (out nil)) + (recur f ((in l) (out Nil)) (if (pair? in) (f (cdr in) (cons (car in) out)) out))) @@ -250,7 +254,7 @@ (else (error 'append "expected proper list")))) (def (zip x y) - (cond ((and (nil? x) (nil? y)) nil) + (cond ((and (nil? x) (nil? y)) Nil) ((or (nil? x) (nil? y)) (error 'zip "given lists of unequal length")) ((and (pair? x) (pair? y)) (cons (cons (car x) (car y)) @@ -258,12 +262,12 @@ ; TODO assoc optional equal? arg (def (assoc key table) - (cond ((nil? table) nil) + (cond ((nil? table) Nil) ((= key (caar table)) (car table)) (else (assoc key (cdr table))))) (def (memp proc lst) - (cond ((nil? lst) nil) + (cond ((nil? lst) Nil) ((proc (car lst)) lst) (else (memp proc (cdr lst))))) @@ -282,6 +286,7 @@ (f (+ n 1) (cdr lst))))) ;;; Stacks + (def (push stack val) (cons val stack)) diff --git a/tib/io.tsp b/tib/io.tsp @@ -1,5 +1,5 @@ (def (run file) (eval (parse (read file)))) -(def (print . str) (apply write (list* 'stdout nil str))) +(def (print . str) (apply write (list* 'stdout Nil str))) (def (newline . file) (if (or (nil? file) (nil? (cdr file))) (write (car (or file '(stdout))) file "\n") @@ -9,7 +9,7 @@ (map (lambda (s) (cond ((string? s) (print "\"" s "\"")) - ((true? s) (print s)) ; don't print 't since it's self evaluating + ((true? s) (print s)) ; don't quote True since it's self evaluating ((symbol? s) (print "'" s)) ((pair? s) (print "'" s)) (else (print s)))) diff --git a/tib/math.c b/tib/math.c @@ -99,12 +99,12 @@ prim_##NAME(Tsp st, Hash vars, Val args) \ } /* define int and dec as identity functions to use them in the same macro */ -#define integer(X) (X) -PRIM_ROUND(integer, 1) -#undef integer -#define decimal(X) (X) -PRIM_ROUND(decimal, 2) -#undef decimal +#define Int(X) (X) +#define Dec(X) (X) +PRIM_ROUND(Int, 1) +PRIM_ROUND(Dec, 2) +#undef Int +#undef Dec PRIM_ROUND(round, 0) PRIM_ROUND(floor, 0) PRIM_ROUND(ceil, 0) @@ -259,8 +259,8 @@ tib_env_math(Tsp st) tsp_env_fn(numerator); tsp_env_fn(denominator); - tsp_env_fn(integer); - tsp_env_fn(decimal); + tsp_env_fn(Int); + tsp_env_fn(Dec); tsp_env_fn(floor); tsp_env_fn(ceil); tsp_env_fn(round); diff --git a/tib/math.tsp b/tib/math.tsp @@ -1,9 +1,11 @@ ;;; Constants + (def pi (* 4 (arctan 1.))) (def tau (* 2 pi)) (def e (exp 1.)) ;;; Functions + (def (inc x) (+ x 1)) (def (dec x) (- x 1)) (def (truncate x) (* (floor (abs x)) (sgn x))) @@ -20,7 +22,8 @@ (defmacro (-- x . n) `(set! ,x (- ,x ,(default n 1)))) -; inverse trig functions +;;; Trig + (def (csc x) (/ (sin x))) (def (arccsc x) (/ (arcsin x))) (def (csch x) (/ (sinh x))) @@ -57,4 +60,3 @@ (if (= n 1) 1 (* n (! (- n 1))))) - diff --git a/tib/repl.tsp b/tib/repl.tsp @@ -10,6 +10,6 @@ ;; simple repl, only requires io.c tib (def (repl-simple) - (write 'stdout nil "> ") - (write 'stdout nil (eval (parse (read))) "\n") + (write 'stdout Nil "> ") + (write 'stdout Nil (eval (parse (read))) "\n") (repl-simple)) diff --git a/tib/string.c b/tib/string.c @@ -85,22 +85,21 @@ val_string(Tsp st, Val args, MkFn mk_fn) return v; } -/* TODO string and symbol: multi arguments to concat */ static Val -prim_string(Tsp st, Hash env, Val args) +prim_Str(Tsp st, Hash env, Val args) { Val v; - tsp_arg_min(args, "string", 1); + tsp_arg_min(args, "Str", 1); if (!(v = tisp_eval_list(st, env, args))) return NULL; return val_string(st, v, mk_str); } static Val -prim_symbol(Tsp st, Hash env, Val args) +prim_Sym(Tsp st, Hash env, Val args) { Val v; - tsp_arg_min(args, "symbol", 1); + tsp_arg_min(args, "Sym", 1); if (!(v = tisp_eval_list(st, env, args))) return NULL; return val_string(st, v, mk_sym); @@ -122,7 +121,7 @@ prim_strlen(Tsp st, Hash env, Val args) void tib_env_string(Tsp st) { - tsp_env_fn(symbol); - tsp_env_fn(string); + tsp_env_fn(Sym); + tsp_env_fn(Str); tsp_env_fn(strlen); } diff --git a/tisp.c b/tisp.c @@ -83,25 +83,25 @@ char * type_str(Type t) { switch (t) { - case NONE: return "void"; - case NIL: return "nil"; - case INTEGER: return "integer"; - case DECIMAL: return "decimal"; - case RATIO: return "ratio"; - case STRING: return "string"; - case SYMBOL: return "symbol"; - case PRIMITIVE: return "primitive"; - case FUNCTION: return "function"; - case MACRO: return "macro"; - case PAIR: return "pair"; + case NONE: return "Void"; + case NIL: return "Nil"; + case INTEGER: return "Int"; + case DECIMAL: return "Dec"; + case RATIO: return "Ratio"; + case STRING: return "Str"; + case SYMBOL: return "Sym"; + case PRIMITIVE: return "Prim"; + case FUNCTION: return "Func"; + case MACRO: return "Macro"; + case PAIR: return "Pair"; default: if (t == EXPRESSION) - return "expression"; + return "Expr"; if (t == RATIONAL) - return "rational"; + return "Rational"; if (t & NUMBER) - return "number"; - return "invalid"; + return "Num"; + return "Invalid"; } } @@ -769,7 +769,7 @@ tisp_print(FILE *f, Val v) fputs("#<void>", f); break; case NIL: - fputs("nil", f); + fputs("Nil", f); break; case INTEGER: fprintf(f, "%d", (int)num(v)); @@ -1144,11 +1144,11 @@ tisp_env_init(size_t cap) st->none->t = NONE; st->t = emalloc(sizeof(struct Val)); st->t->t = SYMBOL; - st->t->v.s = "t"; + st->t->v.s = "True"; st->global = hash_new(cap, NULL); - tisp_env_add(st, "t", st->t); - tisp_env_add(st, "nil", st->nil); + tisp_env_add(st, "True", st->t); + tisp_env_add(st, "Nil", st->nil); tisp_env_add(st, "bt", st->nil); tsp_env_fn(car); tsp_env_fn(cdr);