aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorp4bl0 <r _at_ uzy .dot. me>2012-07-18 16:27:45 (CEST)
committerp4bl0 <r _at_ uzy .dot. me>2012-07-18 16:27:45 (CEST)
commit421c072ed622afee197321259bb3788dd74e9c6a (patch)
treed315d76024d4cf36f66d1fbaff6fca2c5a8102c4
parent818675d539a3b750adaa32268a5fa6cb7297cfc8 (diff)
downloadelispon-421c072ed622afee197321259bb3788dd74e9c6a.zip
elispon-421c072ed622afee197321259bb3788dd74e9c6a.tar.gz
vector->list and list->vector are lib rather than primitives
-rw-r--r--lib/conv.lpn16
-rw-r--r--src/primitive.c3
-rw-r--r--src/primitive.h2
-rw-r--r--src/primitives/conversion.c55
4 files changed, 18 insertions, 58 deletions
diff --git a/lib/conv.lpn b/lib/conv.lpn
new file mode 100644
index 0000000..cca6eac
--- /dev/null
+++ b/lib/conv.lpn
@@ -0,0 +1,16 @@
+(define vector->list
+ (vau args env
+ (sequence
+ (define v (eval (car args) env))
+ (define v->l
+ (vau a e
+ (sequence
+ (define i (eval (car a) e))
+ (define l (cons (v i) (eval (car (cdr a)) e)))
+ (if (= 0 i)
+ l
+ (v->l (- i 1) l)))))
+ (v->l (- (length v) 1) ()))))
+
+(define list->vector
+ (vau args env (eval (cons vector (eval (car args) env)) env)))
diff --git a/src/primitive.c b/src/primitive.c
index bf3e563..330c242 100644
--- a/src/primitive.c
+++ b/src/primitive.c
@@ -140,8 +140,7 @@ Primitive prim_[PRIMITIVE_COUNT] = {
{ "number->string", PrimitiveProc_number_to_string },
{ "string->number", PrimitiveProc_string_to_number },
{ "string->list", PrimitiveProc_string_to_list },
- { "vector->list", PrimitiveProc_vector_to_list },
- { "list->vector", PrimitiveProc_list_to_vector },
+ /* { "list->string", PrimitiveProc_list_to_string }, */
{ "%open-fexpr%", PrimitiveProc_open_fexpr },
{ "%open-struct%", PrimitiveProc_open_struct }
diff --git a/src/primitive.h b/src/primitive.h
index 1e394e1..4e43661 100644
--- a/src/primitive.h
+++ b/src/primitive.h
@@ -7,7 +7,7 @@
#include "environment.h"
#include "eval.h"
-#define PRIMITIVE_COUNT 53
+#define PRIMITIVE_COUNT 51
typedef struct Primitive Primitive;
typedef Expression *(*PrimitiveProc)(Expression *, Environment **, Eval *);
diff --git a/src/primitives/conversion.c b/src/primitives/conversion.c
index 8d4fdc0..8b738cf 100644
--- a/src/primitives/conversion.c
+++ b/src/primitives/conversion.c
@@ -102,58 +102,3 @@ PrimitiveProc_string_to_list (Expression *args, Environment **env, Eval *ev)
return list;
}
-
-static Expression *
-PrimitiveProc_vector_to_list (Expression *args, Environment **env, Eval *ev)
-{
- Expression *expr = NULL, *list = NULL;
- Vector *vector = NULL;
- int i;
-
- nb_args("vector->list", 1, args);
-
- if ((expr = Eval_eval(ev, car(args), env)) == NULL)
- return NULL;
-
- if (Expression_type(expr) != VECTOR) {
- Utils_error("vector->list: expected vector");
- return NULL;
- }
-
- vector = Expression_expr(expr);
- list = Expression_new(NIL, NULL);
- for (i = Vector_size(vector) - 1; i >= 0; i--)
- list = cons(Vector_get(vector, i), list);
-
- return list;
-}
-
-static Expression *
-PrimitiveProc_list_to_vector (Expression *args, Environment **env, Eval *ev)
-{
- Expression *expr = NULL;
- Vector *vector = NULL;
- int i, length;
-
- nb_args("list->vector", 1, args);
-
- if ((expr = Eval_eval(ev, car(args), env)) == NULL)
- return NULL;
-
- if (Expression_type(expr) != PAIR && Expression_type(expr) != NIL) {
- Utils_error("list->vector: expected list");
- return NULL;
- }
-
- i = 0;
- length = Expression_length(expr);
- vector = Vector_new(length);
- if (length > 0) {
- while (Expression_type(expr) == PAIR) {
- Vector_set(vector, i++, car(expr));
- expr = cdr(expr);
- }
- }
-
- return Expression_new(VECTOR, vector);
-}
Pablo Rauzy — generated by cgit