summaryrefslogtreecommitdiff
path: root/liblali.c
diff options
context:
space:
mode:
Diffstat (limited to 'liblali.c')
-rw-r--r--liblali.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/liblali.c b/liblali.c
index 7394ca3..ac552c2 100644
--- a/liblali.c
+++ b/liblali.c
@@ -1041,19 +1041,23 @@ Object *primitiveJoin(Object **args, GC_PARAM) {
exceptionWithObject((*args)->car, "is not a list");
Object *tmpCons = (*args)->car;
+
+ int elementsType = tmpCons->car->type;
+
unsigned long i = strlen(tmpCons->car->string);
- for (; tmpCons->cdr != nil; tmpCons = tmpCons->cdr)
+ for (; tmpCons->cdr != nil; tmpCons = tmpCons->cdr) {
i += strlen(tmpCons->cdr->car->string);
-
+ if (elementsType != tmpCons->cdr->car->type)
+ exception("cannot join list atoms of different type");
+ }
char symbolResult[i+1];
+
tmpCons = (*args)->car;
unsigned long wordLength = strlen(tmpCons->car->string);
unsigned long j = 0;
-
// first list element
for (; j < wordLength; j++)
symbolResult[j] = tmpCons->car->string[j];
-
// rest of list elements
if (tmpCons->cdr->car != nil) {
for (i = wordLength; tmpCons->cdr != nil; tmpCons = tmpCons->cdr) {
@@ -1064,7 +1068,11 @@ Object *primitiveJoin(Object **args, GC_PARAM) {
}
}
symbolResult[i] = '\0';
- return newSymbol(symbolResult, GC_ROOTS);
+
+ if (elementsType == TYPE_STRING)
+ return newString(symbolResult, GC_ROOTS);
+ else
+ return newSymbol(symbolResult, GC_ROOTS);
}
typedef struct Primitive {