klisp

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

commit e75fed6da1649fa472cce34f6e36634de0d75bab
parent 3252fd5b22b628648de4d716bdaf33c7447bd5b4
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 23 Mar 2011 02:46:24 -0300

Added string->list to the ground environment.

Diffstat:
Msrc/kground.c | 2+-
Msrc/kgstrings.c | 21++++++++++++++++++++-
Msrc/kgstrings.h | 3++-
3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/kground.c b/src/kground.c @@ -617,7 +617,7 @@ void kinit_ground_env(klisp_State *K) /* TODO */ /* 13.2.7? string->list, list->string */ - /* TODO */ + add_applicative(K, ground_env, "string->list", string_to_list, 0); add_applicative(K, ground_env, "list->string", list_to_string, 0); /* 13.2.8? string-copy */ diff --git a/src/kgstrings.c b/src/kgstrings.c @@ -185,7 +185,26 @@ void substring(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) /* TODO */ /* 13.2.7? string->list, list->string */ -/* TODO */ +void string_to_list(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + + bind_1tp(K, "string->list", ptree, "string", ttisstring, str); + int32_t pairs = kstring_size(str); + char *buf = kstring_buf(str); + TValue dummy = kcons(K, KINERT, KNIL); + TValue tail = dummy; + + while(pairs--) { + TValue new_pair = kcons(K, ch2tv(*buf), KNIL); + buf++; + kset_cdr(tail, new_pair); + tail = new_pair; + } + kapply_cc(K, kcdr(dummy)); +} void list_to_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) diff --git a/src/kgstrings.h b/src/kgstrings.h @@ -53,9 +53,10 @@ void substring(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* TODO */ /* 13.2.7? string->list, list->string */ -/* TODO */ void list_to_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); +void string_to_list(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv); /* 13.2.8? string-copy */ void string_copy(klisp_State *K, TValue *xparams, TValue ptree, TValue denv);