commit ffb89259cadada9cdaf90f1ea5c599c4f3b0ce8e
parent ed83f3386d60aae9fd66e131bef08c9cf575b00a
Author: Ed van Bruggen <edvb@uw.edu>
Date: Sat, 21 Mar 2020 01:08:43 -0700
Display empty list as nil
Diffstat:
test.c | | | 153 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
tisp.c | | | 2 | +- |
2 files changed, 78 insertions(+), 77 deletions(-)
diff --git a/test.c b/test.c
@@ -56,7 +56,8 @@ char *tests[][2] = {
{ "\"foo\"", "\"foo\"" },
{ "\"foo bar\"", "\"foo bar\"" },
{ "t", "t" },
- { "()", "()" },
+ { "()", "nil" },
+ { "nil", "nil" },
{ "comments", NULL },
{ "; commment", "#<void>" },
@@ -140,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)", "()" },
- { "(= 1 1 2 1 1 1)", "()" },
- { "(= 1 1 1 1 1 2)", "()" },
- { "(= 2 1 1 1 1 1)", "()" },
- { "(= 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)", "()" },
- { "(= 5/4 4/5)", "()" },
- { "(= 3 3/2)", "()" },
- { "(= 3 3/2 3 3 3)", "()" },
- { "(= (+ 1 1) (+ 2 0))", "t" },
- { "(= \"foo\" \"foo\")", "t" },
- { "(= \"foo\" \"bar\")", "()" },
- { "(= \"foo\" \"foo\" \"foo\" \"foo\" \"foo\")", "t" },
- { "(= \"foo\" \"bar\" \"foo\" \"foo\" \"foo\")", "()" },
- { "(= \"foo\" 3)", "()" },
- { "(= \"foo\" \"foo\" 4 \"foo\" \"foo\")", "()" },
- { "(= \"foo\" \"FOO\")", "()" },
- { "(= t t)", "t" },
- { "(= car car)", "t" },
- { "(= car cdr)", "()" },
- { "(= quote quote quote)", "t" },
- { "(= '(1 2 3) '(1 2 3))", "t" },
- { "(= '(a b c) '(a b c))", "t" },
- { "(= '(a b c) '(a b d))", "()" },
- { "(= '(1 2 3) '(1 2))", "()" },
- { "(= '(1 2 3) '(1))", "()" },
- { "(= '((1 2) 3 4) '((1 2) 3 4))", "t" },
- { "(= '((1 b) 3 4) '((1 2) 3 4))", "()" },
+ { "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" },
{ "define", NULL },
{ "(define foo 4)", "#<void>" },
@@ -227,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)", "()" },
- { "(and () ())", "()" },
- { "(and t ())", "()" },
- { "(and () t)", "()" },
- { "(and t t)", "t" },
- { "(nand () ())", "t" },
- { "(nand t ())", "t" },
- { "(nand () t)", "t" },
- { "(nand t t)", "()" },
- { "(or () ())", "()" },
- { "(or t ())", "t" },
- { "(or () t)", "t" },
- { "(or t t)", "t" },
- { "(nor () ())", "t" },
- { "(nor t ())", "()" },
- { "(nor () t)", "()" },
- { "(nor t t)", "()" },
+ { "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" },
{ "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)", "()" },
+ { "(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)" },
@@ -277,7 +278,7 @@ 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)", "()" },
+ { "(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)" },
@@ -312,7 +313,7 @@ char *tests[][2] = {
{ "(reverse '(a b))", "(b a)" },
{ "(reverse (list \"foo\" \"bar\" \"baz\"))", "(\"baz\" \"bar\" \"foo\")" },
{ "(reverse (cons 1/2 nil))", "(1/2)" },
- { "(reverse ())", "()" },
+ { "(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)" },
@@ -323,7 +324,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)))", "()" },
+ { "(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 },
@@ -336,8 +337,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))", "()" },
- { "(member 'qux '(foo bar baz))", "()" },
+ { "(member \"quux\" (list 4.2 3 'quux))", "nil" },
+ { "(member 'qux '(foo bar baz))", "nil" },
{ "quasiquote", NULL },
{ "`7.2", "7.2" },
@@ -485,19 +486,19 @@ char *tests[][2] = {
{ "(mod 7 2)", "1" },
{ "(mod 8 5)", "3" },
- { "compare", NULL },
- { "(< 2 3)", "t" },
- { "(< 3 3)", "()" },
- { "(< 4 3)", "()" },
- { "(<= -2 +4)", "t" },
- { "(<= -2 -2)", "t" },
- { "(<= 4 -2)", "()" },
- { "(> 89 34)", "t" },
- { "(> 48 48)", "()" },
- { "(> 98 183)", "()" },
- { "(>= +4 -282)", "t" },
- { "(>= 39 39)", "t" },
- { "(>= -32 -30)", "()" },
+ { "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" },
{ "abs", NULL },
{ "(abs 4)", "4" },
diff --git a/tisp.c b/tisp.c
@@ -756,7 +756,7 @@ tisp_print(FILE *f, Val v)
fputs("#<void>", f);
break;
case NIL:
- fputs("()", f);
+ fputs("nil", f);
break;
case INTEGER:
fprintf(f, "%d", (int)num(v));