diff options
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | liblali.c | 25 | ||||
-rw-r--r-- | liblali.h | 2 |
3 files changed, 30 insertions, 3 deletions
@@ -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) @@ -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. @@ -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 |