klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 90ee297ab888cd8b43860e8589bea55f7a0e4210
parent 87a85e4c4b699d679d82a5ac46751a011113b394
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu, 24 Mar 2011 16:17:31 -0300

Added and? to the ground environment.

Diffstat:
Msrc/kgbooleans.c | 33+++++++++++++++++++++++++++++++++
Msrc/kgbooleans.h | 15+++++++++++++++
Msrc/kground.c | 2+-
3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/kgbooleans.c b/src/kgbooleans.c @@ -32,3 +32,36 @@ void notp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) TValue res = kis_true(tv_b)? KFALSE : KTRUE; kapply_cc(K, res); } + +/* Helper for type checking booleans */ +bool kbooleanp(TValue obj) { return ttisboolean(obj); } + +/* 6.1.2 and? */ +void andp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + int32_t dummy; /* don't care about cycle pairs */ + int32_t pairs = check_typed_list(K, "andp", "boolean", kbooleanp, + true, ptree, &dummy); + TValue res = KTRUE; + TValue tail = ptree; + while(pairs--) { + TValue first = kcar(tail); + tail = kcdr(tail); + if (kis_false(first)) { + res = KFALSE; + break; + } + } + kapply_cc(K, res); +} + +/* 6.1.3 or? */ +/* TODO */ + +/* 6.1.4 $and? */ +/* TODO */ + +/* 6.1.5 $or? */ +/* TODO */ diff --git a/src/kgbooleans.h b/src/kgbooleans.h @@ -24,4 +24,19 @@ /* 6.1.1 not? */ void notp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); +/* 6.1.2 and? */ +void andp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + +/* 6.1.3 or? */ +/* TODO */ + +/* 6.1.4 $and? */ +/* TODO */ + +/* 6.1.5 $or? */ +/* TODO */ + +/* Helper */ +bool kbooleanp(TValue obj); + #endif diff --git a/src/kground.c b/src/kground.c @@ -352,7 +352,7 @@ void kinit_ground_env(klisp_State *K) add_applicative(K, ground_env, "not?", notp, 0); /* 6.1.2 and? */ - /* TODO */ + add_applicative(K, ground_env, "and?", andp, 0); /* 6.1.3 or? */ /* TODO */