summaryrefslogtreecommitdiff
path: root/liblali.c
diff options
context:
space:
mode:
Diffstat (limited to 'liblali.c')
-rw-r--r--liblali.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/liblali.c b/liblali.c
index 561aac4..9fc2cdb 100644
--- a/liblali.c
+++ b/liblali.c
@@ -1092,19 +1092,47 @@ Object *primitiveSplit(Object **args, GC_PARAM) {
symbol->type != TYPE_NUMBER))
exceptionWithObject(symbol, "is not a symbol, not a number, not a string");
+ bool hasDot = false;
+ if (symbol->type == TYPE_NUMBER)
+ hasDot = (hasADot(symbol->string)) ? true : false;
+
GC_TRACE(gcRes, nil);
+ GC_TRACE(gcList, nil);
GC_TRACE(gcElement, nil);
- char string[2] = {'\0'};
+ char string[3] = {'\0'};
size_t size = strlen(symbol->string);
+ bool numberPrefix = (symbol->type == TYPE_NUMBER) ? true : false;
for (unsigned long i = 0; i < size; i++) {
string[0] = symbol->string[i];
+ if (numberPrefix) {
+ *gcElement = newSymbol(string, GC_ROOTS);
+ *gcRes = newCons(gcElement, gcRes, GC_ROOTS);
+ numberPrefix = false;
+ continue;
+ } else if (hasDot && symbol->string[i] == '.') {
+ *gcList = reverseList(*gcList);
+ *gcRes = newCons(gcList, gcRes, GC_ROOTS);
+ *gcList = nil;
+ continue;
+ }
+
if (symbol->type == TYPE_STRING)
*gcElement = newString(string, GC_ROOTS);
- else
+ else if (symbol->type == TYPE_NUMBER) {
+ string[0] = '+';
+ string[1] = symbol->string[i];
+ *gcElement = newNumber(string, GC_ROOTS);
+ *gcList = newCons(gcElement, gcList, GC_ROOTS);
+ continue;
+ } else
*gcElement = newSymbol(string, GC_ROOTS);
*gcRes = newCons(gcElement, gcRes, GC_ROOTS);
}
+ if (symbol->type == TYPE_NUMBER) {
+ *gcList = reverseList(*gcList);
+ *gcRes = newCons(gcList, gcRes, GC_ROOTS);
+ }
return reverseList(*gcRes);
}