klisp

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

commit 43a49653ae06132cc4570bd4c42dc186df6d2dd1
parent 5ec015823547ac323080a0f66fbaa2793f742b7e
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu, 24 Mar 2011 16:27:32 -0300

Added length to the ground environment.

Diffstat:
Msrc/kgpairs_lists.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/kgpairs_lists.h | 33+++++++++++++++++++++++++++++++--
Msrc/kground.c | 2+-
3 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/src/kgpairs_lists.c b/src/kgpairs_lists.c @@ -208,3 +208,51 @@ void list_tail(klisp_State *K, TValue *xparams, TValue ptree, } kapply_cc(K, obj); } + +/* 6.3.1 length */ +void length(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + + bind_1p(K, "length", ptree, obj); + + TValue tail = obj; + int pairs = 0; + while(ttispair(tail) && !kis_marked(tail)) { + kmark(tail); + tail = kcdr(tail); + ++pairs; + } + unmark_list(K, obj); + + TValue res = ttispair(tail)? KEPINF : i2tv(pairs); + kapply_cc(K, res); +} + +/* 6.3.2 list-ref */ +/* TODO */ + +/* 6.3.3 append */ +/* TODO */ + +/* 6.3.4 list-neighbors */ +/* TODO */ + +/* 6.3.5 filter */ +/* TODO */ + +/* 6.3.6 assoc */ +/* TODO */ + +/* 6.3.7 member? */ +/* TODO */ + +/* 6.3.8 finite-list? */ +/* TODO */ + +/* 6.3.9 countable-list? */ +/* TODO */ + +/* 6.3.10 reduce */ +/* TODO */ diff --git a/src/kgpairs_lists.h b/src/kgpairs_lists.h @@ -52,7 +52,36 @@ void get_list_metrics(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 5.7.2 list-tail */ -void list_tail(klisp_State *K, TValue *xparams, TValue ptree, - TValue denv); +void list_tail(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + +/* 6.3.1 length */ +void length(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); + +/* 6.3.2 list-ref */ +/* TODO */ + +/* 6.3.3 append */ +/* TODO */ + +/* 6.3.4 list-neighbors */ +/* TODO */ + +/* 6.3.5 filter */ +/* TODO */ + +/* 6.3.6 assoc */ +/* TODO */ + +/* 6.3.7 member? */ +/* TODO */ + +/* 6.3.8 finite-list? */ +/* TODO */ + +/* 6.3.9 countable-list? */ +/* TODO */ + +/* 6.3.10 reduce */ +/* TODO */ #endif diff --git a/src/kground.c b/src/kground.c @@ -376,7 +376,7 @@ void kinit_ground_env(klisp_State *K) */ /* 6.3.1 length */ - /* TODO */ + add_applicative(K, ground_env, "length", length, 0); /* 6.3.2 list-ref */ /* TODO */