summaryrefslogtreecommitdiff
path: root/src/scheme/ao_scheme_vector.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-01-03 14:57:39 -0800
committerKeith Packard <keithp@keithp.com>2018-01-03 14:58:30 -0800
commit7bfc1eda398e8767e352cd6396ac61c7ea021079 (patch)
tree92cb1bdf77bd1862bd0b79f1bc196715871a2958 /src/scheme/ao_scheme_vector.c
parent2bcc178f3cbfd346b134bb3fe700b0512f340fea (diff)
altos/scheme: Add start/end args to vector->list
This is an r7rs extension which allows you to extract a subset of the vector. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_vector.c')
-rw-r--r--src/scheme/ao_scheme_vector.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/scheme/ao_scheme_vector.c b/src/scheme/ao_scheme_vector.c
index afdc89a8..083823f3 100644
--- a/src/scheme/ao_scheme_vector.c
+++ b/src/scheme/ao_scheme_vector.c
@@ -159,13 +159,19 @@ ao_scheme_list_to_vector(struct ao_scheme_cons *cons)
}
struct ao_scheme_cons *
-ao_scheme_vector_to_list(struct ao_scheme_vector *vector)
+ao_scheme_vector_to_list(struct ao_scheme_vector *vector, int start, int end)
{
- unsigned int i;
+ int i;
uint16_t length = vector->length;
struct ao_scheme_cons *cons = NULL;
- for (i = length; i-- > 0;) {
+ if (end == -1)
+ end = length;
+ if (start < 0)
+ start = 0;
+ if (end > length)
+ end = length;
+ for (i = end; i-- > start;) {
ao_scheme_vector_stash(vector);
cons = ao_scheme_cons_cons(vector->vals[i], ao_scheme_cons_poly(cons));
vector = ao_scheme_vector_fetch();