From 875228a2b68c4a2eebc7a3468b47ae65658402b8 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 2 Nov 2020 15:29:03 -0500 Subject: [PATCH] Add `isstr` to type-checking collection --- src/env.c | 2 +- src/pebblisp.c | 6 ++++++ src/pebblisp.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/env.c b/src/env.c index ed0dcf8..7851eed 100644 --- a/src/env.c +++ b/src/env.c @@ -229,7 +229,7 @@ struct Environment defaultEnv() {"cat", &catObjects}, {"fil", &filter}, {"len", &len}, {"ap", &append}, {"pre", &prepend}, {"at", &at}, {"rest", &rest}, {"rev", &reverse}, - {"isnum", &isNum}, + {"isnum", &isNum}, {"isstr", &isString}, {"prn", &print}, {"penv", &printEnvO}, }; diff --git a/src/pebblisp.c b/src/pebblisp.c index dbf09fe..ff53fe3 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -392,6 +392,12 @@ Object isNum(Object test, Object ignore, struct Environment *ignore2) boolObject(1) : boolObject(0); } +Object isString(Object test, Object ignore, struct Environment *ignore2) +{ + return test.type == TYPE_STRING ? + boolObject(1) : boolObject(0); +} + Object print(Object p, Object ignore, struct Environment *env) { p = cloneObject(p); diff --git a/src/pebblisp.h b/src/pebblisp.h index e128ac7..4d93924 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -56,6 +56,7 @@ 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); +Object isString(Object test, Object ignore, struct Environment *ignore2); Object print(Object p, Object ignore, struct Environment *ignore2); Object printEnvO(Object i1, Object i2, struct Environment *env);