X-Git-Url: https://jxself.org/git/?p=mes.git;a=blobdiff_plain;f=lib.c;h=b252ef1a014e8cce6b0ccdda49ad874492e93f11;hp=4d7a617645dd42279652207ada2624ca9fd23447;hb=3b4e9f36c87ca1d216619bfbbfc2a3d48478f294;hpb=6a4395869bbbbce2019116d0dc0d3a81c655dbd9 diff --git a/lib.c b/lib.c index 4d7a6176..b252ef1a 100644 --- a/lib.c +++ b/lib.c @@ -56,12 +56,25 @@ list (scm *x) ///((args . n)) return x; } +scm * +list_ref (scm *x, scm *k) +{ + assert (x->type == PAIR); + assert (k->type == NUMBER); + int n = k->value; + while (n-- && x->cdr != &scm_nil) x = x->cdr; + return x != &scm_nil ? x->car : &scm_undefined; +} + scm * vector_to_list (scm *v) { scm *x = &scm_nil; - for (int i = 0; i < v->length; i++) - x = append2 (x, cons (v->vector[i], &scm_nil)); + for (int i = 0; i < v->length; i++) { + scm *e = &v->vector[i]; + if (e->type == REF) e = e->ref; + x = append2 (x, cons (e, &scm_nil)); + } return x; }