commit ea22406861db22b957757dd694b0f04debcf5de8
parent ab898691660f63ec16f66fe5047e2be0f4b3f54d
Author: Ed van Bruggen <edvb@uw.edu>
Date: Tue, 6 Oct 2020 19:12:36 -0700
Capitalize void, bool, and pair type creators
Diffstat:
6 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/doc/tisp.1.md b/doc/tisp.1.md
@@ -177,7 +177,7 @@ as the cdr. Can be chained together to create a list if ending with `nil`.
Returns the given argument unevaluated.
-#### void
+#### Void
Returns nothing. Used to insert a void type in a list or force a function not
to return anything.
diff --git a/test.c b/test.c
@@ -102,12 +102,12 @@ char *tests[][2] = {
{ "(cdr (cdr (cons 1 (cons 2 3))))", "3" },
{ "void", NULL },
- { "(void)", "#<void>" },
+ { "(Void)", "#<void>" },
{ "do", NULL },
{ "(do (+ 1 2) (+ 2 2))", "4" },
{ "(do (+ -4 8) (- 1 2) (* 80 0) (+ 39 -3))", "36" },
- { "(do (mod 80 2) (/ 4 2) (void))", "#<void>" },
+ { "(do (mod 80 2) (/ 4 2) (Void))", "#<void>" },
{ "eval", NULL },
{ "(eval ''hey)", "hey" },
diff --git a/tib/core.tsp b/tib/core.tsp
@@ -41,7 +41,7 @@
(def (void? x) (= (typeof x) "Void"))
(def (nil? x) (= (typeof x) "Nil"))
(def empty? nil?)
-(def (integer? x) (= (typeof x) "Int"))
+(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"))
@@ -60,9 +60,9 @@
(def (rational? x) (or (integer? x) (ratio? x)))
(def (number? x) (or (rational? x) (decimal? x)))
-(def (bool x) (if x True Nil))
+(def (Bool x) (if x True Nil))
; TODO handle string and sym
-(def (pair x)
+(def (Pair x)
(cond
((rational? x)
(cons (numerator x)
@@ -71,7 +71,7 @@
(cons (integer (truncate x))
(- x (truncate x))))
((or (void? x) (nil? x) (pair? x)) x)
- (else (list x))))
+ (else (cons x Nil))))
(defmacro (assert expr)
`(unless ,expr
diff --git a/tib/doc.tsp b/tib/doc.tsp
@@ -11,9 +11,10 @@
(quote
"(quote expr)"
"return expression unevaluated")
- (void
- "(void)"
- "return void type")
+ (Void
+ "(Void)"
+ "return nothing"
+ "used to insert a void type in a list or force a function not to return anything")
(eval
"(eval expr)"
"evaluate expression, can be dangerous to use in practice")
@@ -71,4 +72,4 @@
docstr)
(lookup proc)))
(lookup proc))
- (void))
+ (Void))
diff --git a/tib/string.c b/tib/string.c
@@ -41,12 +41,12 @@ val_string(Tsp st, Val args, MkFn mk_fn)
case NONE:
len += 5;
ret = realloc(ret, len*sizeof(char));
- strcat(ret, "void");
+ strcat(ret, "Void");
break;
case NIL:
len += 4;
ret = realloc(ret, len*sizeof(char));
- strcat(ret, "nil");
+ strcat(ret, "Nil");
break;
case INTEGER:
snprintf(s, 21, "%d", (int)v->v.n.num);
diff --git a/tisp.c b/tisp.c
@@ -860,7 +860,7 @@ prim_quote(Tsp st, Hash env, Val args)
/* returns nothing */
static Val
-prim_void(Tsp st, Hash env, Val args)
+prim_Void(Tsp st, Hash env, Val args)
{
return st->none;
}
@@ -1148,7 +1148,7 @@ tisp_env_init(size_t cap)
tsp_env_fn(cdr);
tsp_env_fn(cons);
tsp_env_fn(quote);
- tsp_env_fn(void);
+ tsp_env_fn(Void);
tsp_env_fn(eval);
tsp_env_name_fn(=, eq);
tsp_env_fn(cond);