Skip to content

Instantly share code, notes, and snippets.

@mathias
Created December 5, 2014 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathias/9e6773508969e06c62e7 to your computer and use it in GitHub Desktop.
Save mathias/9e6773508969e06c62e7 to your computer and use it in GitHub Desktop.
lval* builtin_join_str(lenv* e, lval* a) {
for(int i = 0; i < a->count; i++) {
LASSERT_TYPE("join", a, i, LVAL_STR);
}
lval* x = lval_pop(a, 0);
while (a->count) {
lval* y = lval_pop(a, 0);
char* concatted = malloc(strlen(x->str) + strlen(y->str) + 1);
concatted = strcat(x->str, y->str);
x = lval_str(concatted);
free(concatted);
free(y);
}
lval_del(a);
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment