From 7b649fdf1688c3fe11933ebb0254377633428811 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 28 Oct 2020 18:08:03 -0400 Subject: [PATCH] Add `isnum` and some tests --- src/env.c | 1 + src/pebblisp.c | 6 ++++++ src/pebblisp.h | 2 ++ src/tests.sh | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/src/env.c b/src/env.c index 1be57da..8d048d1 100644 --- a/src/env.c +++ b/src/env.c @@ -189,6 +189,7 @@ struct Environment defaultEnv() {"=", &equ}, {">", >h}, {"<", <h}, {"cat", &catObjects}, {"fil", &filter}, {"len", &len}, {"ap", &append}, {"at", &at}, {"rest", &rest}, {"rev", &reverse}, + {"isnum", &isNum}, }; for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) { diff --git a/src/pebblisp.c b/src/pebblisp.c index 124d099..441ba59 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -364,6 +364,12 @@ Object reverse(Object _list, Object ignore, struct Environment *ignore2) return rev; } +Object isNum(Object test, Object ignore, struct Environment *ignore2) +{ + return test.type == TYPE_NUMBER ? + boolObject(1) : boolObject(0); +} + void copySlice(char * dest, struct Slice *src) { if(!dest || !src) diff --git a/src/pebblisp.h b/src/pebblisp.h index a76d7ca..6c9ac57 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -54,4 +54,6 @@ Object at(Object index, Object list, struct Environment *env); Object rest(Object list, Object ignore, struct Environment *env); Object reverse(Object _list, Object ignore, struct Environment *ignore2); +Object isNum(Object test, Object ignore, struct Environment *ignore2); + #endif diff --git a/src/tests.sh b/src/tests.sh index cbae38f..4689f16 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -86,6 +86,11 @@ check "StringEquality" "(= \"Bean\" \"Bean\" )" "T" check "StringInequality" "(= \"Beans\" \"Bean\" )" "F" endBlock +title "TypeCheck" +check "IsNum" "(isnum 23847123)" "T" +check "IsntNum" "(isnum \"WORDS\")" "F" +endBlock + title "Ifs/Bools" check "IfReturn" "(if (T) 123456789 987654321)" "123456789" check "IfRetTwo" "(if F 123456789 987654321)" "987654321"