Add `isnum` and some tests
This commit is contained in:
parent
ca51937926
commit
7b649fdf16
|
@ -189,6 +189,7 @@ struct Environment defaultEnv()
|
||||||
{"=", &equ}, {">", >h}, {"<", <h},
|
{"=", &equ}, {">", >h}, {"<", <h},
|
||||||
{"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++) {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue