summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Cerqueira <dan.git@lispclub.com>2025-06-11 11:37:04 +0100
committerDaniel Cerqueira <dan.git@lispclub.com>2025-06-11 11:42:08 +0100
commit7f7d6d48b1a5b11c47b36b0472301e884802a2f7 (patch)
treee7d588da6c42cfe963a4e5fb4bbc28afabfb0eb2
parent41746066d99b0a0613205f04c9ad868e7a7336cb (diff)
finalize primitiveSplit()
-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);
}