From 54e2e09c5c0944c419abc20159a7ab5dd5417d1e Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 30 Oct 2020 14:36:44 -0400 Subject: [PATCH] Add explicit (print) function --- src/env.c | 1 + src/pebblisp.c | 9 +++++++++ src/pebblisp.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/env.c b/src/env.c index 5ed0f35..1dc2b10 100644 --- a/src/env.c +++ b/src/env.c @@ -196,6 +196,7 @@ struct Environment defaultEnv() {"ap", &append}, {"pre", &prepend}, {"at", &at}, {"rest", &rest}, {"rev", &reverse}, {"isnum", &isNum}, + {"prn", &print}, }; for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) { diff --git a/src/pebblisp.c b/src/pebblisp.c index d0789a3..d65e74c 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -378,6 +378,15 @@ Object isNum(Object test, Object ignore, struct Environment *ignore2) boolObject(1) : boolObject(0); } +Object print(Object p, Object ignore, struct Environment *env) +{ + p = cloneObject(p); + p = eval(&p, env); + printObj(&p); + printf("\n"); + return p; +} + void copySlice(char * dest, struct Slice *src) { if(!dest || !src) diff --git a/src/pebblisp.h b/src/pebblisp.h index 556bb80..7fc33b5 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -57,4 +57,6 @@ Object reverse(Object _list, Object ignore, struct Environment *ignore2); Object isNum(Object test, Object ignore, struct Environment *ignore2); +Object print(Object p, Object ignore, struct Environment *ignore2); + #endif