| 450 |
/* Gets the type of a value */ |
/* Gets the type of a value */ |
| 451 |
extern void type(environment *env) |
extern void type(environment *env) |
| 452 |
{ |
{ |
|
int typenum; |
|
|
|
|
| 453 |
if(env->head->type==empty) { |
if(env->head->type==empty) { |
| 454 |
printerr("Too Few Arguments"); |
printerr("Too Few Arguments"); |
| 455 |
env->err= 1; |
env->err= 1; |
| 456 |
return; |
return; |
| 457 |
} |
} |
| 458 |
|
|
| 459 |
typenum= CAR(env->head)->type; |
switch(CAR(env->head)->type){ |
| 460 |
toss(env); |
case empty: |
| 461 |
switch(typenum){ |
push_sym(env, "empty"); |
| 462 |
|
break; |
| 463 |
case integer: |
case integer: |
| 464 |
push_sym(env, "integer"); |
push_sym(env, "integer"); |
| 465 |
break; |
break; |
| 479 |
push_sym(env, "list"); |
push_sym(env, "list"); |
| 480 |
break; |
break; |
| 481 |
} |
} |
| 482 |
|
swap(env); |
| 483 |
|
if (env->err) return; |
| 484 |
|
toss(env); |
| 485 |
} |
} |
| 486 |
|
|
| 487 |
/* Prints the top element of the stack. */ |
/* Prints the top element of the stack. */ |
| 488 |
void print_h(value *stack_head, int noquote) |
void print_h(value *stack_head, int noquote) |
| 489 |
{ |
{ |
| 490 |
switch(CAR(stack_head)->type) { |
switch(CAR(stack_head)->type) { |
| 491 |
|
case empty: |
| 492 |
|
printf("[]"); |
| 493 |
|
break; |
| 494 |
case integer: |
case integer: |
| 495 |
printf("%d", CAR(stack_head)->content.i); |
printf("%d", CAR(stack_head)->content.i); |
| 496 |
break; |
break; |
| 499 |
break; |
break; |
| 500 |
case string: |
case string: |
| 501 |
if(noquote) |
if(noquote) |
| 502 |
printf("%s", (char*)CAR(stack_head)->content.ptr); |
printf("%s", (char*)(CAR(stack_head)->content.ptr)); |
| 503 |
else |
else |
| 504 |
printf("\"%s\"", (char*)CAR(stack_head)->content.ptr); |
printf("\"%s\"", (char*)(CAR(stack_head)->content.ptr)); |
| 505 |
break; |
break; |
| 506 |
case symb: |
case symb: |
| 507 |
printf("%s", CAR(stack_head)->content.sym->id); |
printf("%s", CAR(stack_head)->content.sym->id); |
| 513 |
/* A list is just a stack, so make stack_head point to it */ |
/* A list is just a stack, so make stack_head point to it */ |
| 514 |
stack_head= CAR(stack_head); |
stack_head= CAR(stack_head); |
| 515 |
printf("[ "); |
printf("[ "); |
| 516 |
while(CAR(stack_head)->type != empty) { |
while(stack_head->type != empty) { |
| 517 |
print_h(stack_head, noquote); |
print_h(stack_head, noquote); |
| 518 |
if(CDR(stack_head)->type==tcons) |
switch(CDR(stack_head)->type){ |
| 519 |
|
case empty: |
| 520 |
|
break; |
| 521 |
|
case tcons: |
| 522 |
printf(" "); |
printf(" "); |
| 523 |
else |
break; |
| 524 |
|
default: |
| 525 |
printf(" . "); /* Improper list */ |
printf(" . "); /* Improper list */ |
| 526 |
|
} |
| 527 |
stack_head= CDR(stack_head); |
stack_head= CDR(stack_head); |
| 528 |
} |
} |
| 529 |
printf(" ]"); |
printf(" ]"); |