--- stack/stack.c 2002/03/16 19:09:54 1.111 +++ stack/stack.c 2002/03/16 20:09:51 1.112 @@ -450,17 +450,16 @@ /* Gets the type of a value */ extern void type(environment *env) { - int typenum; - if(env->head->type==empty) { printerr("Too Few Arguments"); env->err= 1; return; } - typenum= CAR(env->head)->type; - toss(env); - switch(typenum){ + switch(CAR(env->head)->type){ + case empty: + push_sym(env, "empty"); + break; case integer: push_sym(env, "integer"); break; @@ -480,12 +479,18 @@ push_sym(env, "list"); break; } + swap(env); + if (env->err) return; + toss(env); } /* Prints the top element of the stack. */ void print_h(value *stack_head, int noquote) { switch(CAR(stack_head)->type) { + case empty: + printf("[]"); + break; case integer: printf("%d", CAR(stack_head)->content.i); break; @@ -494,9 +499,9 @@ break; case string: if(noquote) - printf("%s", (char*)CAR(stack_head)->content.ptr); + printf("%s", (char*)(CAR(stack_head)->content.ptr)); else - printf("\"%s\"", (char*)CAR(stack_head)->content.ptr); + printf("\"%s\"", (char*)(CAR(stack_head)->content.ptr)); break; case symb: printf("%s", CAR(stack_head)->content.sym->id); @@ -508,12 +513,17 @@ /* A list is just a stack, so make stack_head point to it */ stack_head= CAR(stack_head); printf("[ "); - while(CAR(stack_head)->type != empty) { + while(stack_head->type != empty) { print_h(stack_head, noquote); - if(CDR(stack_head)->type==tcons) + switch(CDR(stack_head)->type){ + case empty: + break; + case tcons: printf(" "); - else + break; + default: printf(" . "); /* Improper list */ + } stack_head= CDR(stack_head); } printf(" ]"); @@ -1040,7 +1050,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.111 $\n\ + printf("Stack version $Revision: 1.112 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ Stack comes with ABSOLUTELY NO WARRANTY; for details type 'warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\