Skip to content

Instantly share code, notes, and snippets.

@adamczykm
Created August 6, 2015 09:54
Show Gist options
  • Save adamczykm/e8175ef6b259fd664c5d to your computer and use it in GitHub Desktop.
Save adamczykm/e8175ef6b259fd664c5d to your computer and use it in GitHub Desktop.
+(NSObject*)extractSexp:(const Sexp*)s{
if(s==NULL) return nil;
switch (s->type) {
case Bool:
return [NSNumber numberWithBool:(*(int*)s->value)!=0];
case Integer:
return [NSNumber numberWithInteger:(*(int*)s->value)];
case Double:
return [NSNumber numberWithDouble:(*(double*)s->value)];
case String:
case Symbol:
case Keyword:
return [NSString stringWithCString:s->value encoding:NSUTF8StringEncoding];
case List:{
size_t sz = s->value_size;
if(sz == 0){
return nil;
}
if (s->subexps_head->type == SpecialForm &&
*(SpecialType*)s->subexps_head->value == SpecialQuote) {
return [LucidUtils extractSexp:s->subexps_head->next];
}
Sexp* tmp = s->subexps_head;
NSMutableArray* arr = [[NSMutableArray alloc]init];
for (size_t i=0; i<sz; i++) {
[arr addObject:[LucidUtils extractSexp:tmp]];
tmp=tmp->next;
}
return arr;
}
default:
printf("Error: extraction not supported from type: %d", s->type);
break;
}
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment