From 7f7d6d48b1a5b11c47b36b0472301e884802a2f7 Mon Sep 17 00:00:00 2001 From: Daniel Cerqueira Date: Wed, 11 Jun 2025 11:37:04 +0100 Subject: finalize primitiveSplit() --- liblali.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'liblali.c') 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); } -- cgit