This commit is contained in:
Sage Vaillancourt 2020-10-29 09:06:28 -04:00
commit 130da5a70e
4 changed files with 14 additions and 0 deletions

View File

@ -189,6 +189,7 @@ struct Environment defaultEnv()
{"=", &equ}, {">", &gth}, {"<", &lth}, {"=", &equ}, {">", &gth}, {"<", &lth},
{"cat", &catObjects}, {"fil", &filter}, {"len", &len}, {"ap", &append}, {"cat", &catObjects}, {"fil", &filter}, {"len", &len}, {"ap", &append},
{"at", &at}, {"rest", &rest}, {"rev", &reverse}, {"at", &at}, {"rest", &rest}, {"rev", &reverse},
{"isnum", &isNum},
}; };
for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) { for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) {

View File

@ -364,6 +364,12 @@ Object reverse(Object _list, Object ignore, struct Environment *ignore2)
return rev; 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) void copySlice(char * dest, struct Slice *src)
{ {
if(!dest || !src) if(!dest || !src)

View File

@ -54,4 +54,6 @@ Object at(Object index, Object list, struct Environment *env);
Object rest(Object list, Object ignore, struct Environment *env); Object rest(Object list, Object ignore, struct Environment *env);
Object reverse(Object _list, Object ignore, struct Environment *ignore2); Object reverse(Object _list, Object ignore, struct Environment *ignore2);
Object isNum(Object test, Object ignore, struct Environment *ignore2);
#endif #endif

View File

@ -86,6 +86,11 @@ check "StringEquality" "(= \"Bean\" \"Bean\" )" "T"
check "StringInequality" "(= \"Beans\" \"Bean\" )" "F" check "StringInequality" "(= \"Beans\" \"Bean\" )" "F"
endBlock endBlock
title "TypeCheck"
check "IsNum" "(isnum 23847123)" "T"
check "IsntNum" "(isnum \"WORDS\")" "F"
endBlock
title "Ifs/Bools" title "Ifs/Bools"
check "IfReturn" "(if (T) 123456789 987654321)" "123456789" check "IfReturn" "(if (T) 123456789 987654321)" "123456789"
check "IfRetTwo" "(if F 123456789 987654321)" "987654321" check "IfRetTwo" "(if F 123456789 987654321)" "987654321"