diff --git a/mes/module/mes/scm.mes b/mes/module/mes/scm.mes index 3ca92ca1..c4d78035 100644 --- a/mes/module/mes/scm.mes +++ b/mes/module/mes/scm.mes @@ -194,9 +194,6 @@ (define (make-string n . fill) (list->string (apply make-list n fill))) -(define (string-ref s k) - (list-ref (string->list s) k)) - (define (string-set! s k v) (list->string (list-set! (string->list s) k v))) diff --git a/src/mes.c b/src/mes.c index e1752c94..32bfd7ee 100644 --- a/src/mes.c +++ b/src/mes.c @@ -1258,6 +1258,8 @@ eval_apply () goto begin; } } + // write_error_ (CAR (r1)); + // eputs ("\n"); push_cc (CAR (r1), r1, r0, cell_vm_apply2); goto eval; apply2: diff --git a/src/strings.c b/src/strings.c index 9073c2a9..86828461 100644 --- a/src/strings.c +++ b/src/strings.c @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include + #define MAX_STRING 4096 char const* @@ -267,3 +269,16 @@ string_length (SCM string) assert (TYPE (string) == TSTRING); return MAKE_NUMBER (LENGTH (string)); } + +SCM +string_ref (SCM str, SCM k) +{ + assert (TYPE (str) == TSTRING); + assert (TYPE (k) == TNUMBER); + size_t size = LENGTH (str); + size_t i = VALUE (k); + if (i >= size) + error (cell_symbol_system_error, cons (MAKE_STRING0 ("value out of range"), k)); + char const *p = CSTRING (str); + return MAKE_CHAR (p[i]); +}