summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO6
-rw-r--r--liblali.c25
-rw-r--r--liblali.h2
3 files changed, 30 insertions, 3 deletions
diff --git a/TODO b/TODO
index 1fea73e..9b7a05e 100644
--- a/TODO
+++ b/TODO
@@ -1,14 +1,14 @@
maybe make the repl use the readline library.
-create lisp code for addition.
use secure functions.
make quest a thing.
remove macros?
-split, join.
-make unit testing.
instead of returning "#<Lambda ..." it should return the expression.
remove lambda_type and macro_type.
+create lisp code for addition.
+make unit testing.
+split, join. (done)
make numbers be symbols. (done)
make number symbols neutral. (done)
fix a security bug of setting a primitive. (done)
diff --git a/liblali.c b/liblali.c
index ac552c2..9afec71 100644
--- a/liblali.c
+++ b/liblali.c
@@ -1075,6 +1075,30 @@ Object *primitiveJoin(Object **args, GC_PARAM) {
return newSymbol(symbolResult, GC_ROOTS);
}
+Object *primitiveSplit(Object **args, GC_PARAM) {
+ Object *symbol = (*args)->car;
+
+ if (symbol == nil || (symbol->type != TYPE_SYMBOL &&
+ symbol->type != TYPE_STRING &&
+ symbol->type != TYPE_NUMBER))
+ exceptionWithObject(symbol, "is not a symbol, not a number, not a string");
+
+ GC_TRACE(gcRes, nil);
+ GC_TRACE(gcElement, nil);
+ char string[2] = {'\0'};
+ size_t size = strlen(symbol->string);
+ for (unsigned long i = 0; i < size; i++) {
+ string[0] = symbol->string[i];
+ if (symbol->type == TYPE_STRING)
+ *gcElement = newString(string, GC_ROOTS);
+ else
+ *gcElement = newSymbol(string, GC_ROOTS);
+
+ *gcRes = newCons(gcElement, gcRes, GC_ROOTS);
+ }
+ return reverseList(*gcRes);
+}
+
typedef struct Primitive {
char *name;
int nMinArgs, nMaxArgs;
@@ -1118,6 +1142,7 @@ Primitive primitives[] = {
{ ">", 1, -1, primitiveGreater },
/* { ">=", 1, -1, primitiveGreaterEqual } */
{ "join", 1, 1, primitiveJoin },
+ { "split", 1, 1, primitiveSplit },
};
// Special forms handled by evalExpr. Must be in the same order as above.
diff --git a/liblali.h b/liblali.h
index a9b17d0..d1d7c24 100644
--- a/liblali.h
+++ b/liblali.h
@@ -333,6 +333,8 @@ Object *primitiveGreater(Object **args, GC_PARAM);
Object *primitiveJoin(Object **args, GC_PARAM);
+Object *primitiveSplit(Object **args, GC_PARAM);
+
// EVALUATION /////////////////////////////////////////////////////////////////
/* Scheme-style tail recursive evaluation. evalProg, evalProgs, evalCond, and