--- stack/stack.c 2002/03/20 17:19:46 1.119 +++ stack/stack.c 2002/03/21 03:19:32 1.120 @@ -1109,7 +1109,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.119 $\n\ + printf("Stack version $Revision: 1.120 $\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\ @@ -2451,6 +2451,13 @@ /* 1: [ [ 1 . 2 ] [ 3 . 4 ] ] => 1: [ 3 . 4 ] */ extern void assq(environment *env) { + assocgen(env, eq); +} + + +/* General assoc function */ +void assocgen(environment *env, funcp eqfunc) +{ value *key, *item; /* Needs two values on the stack, the top one must be an association @@ -2478,13 +2485,32 @@ } push_val(env, key); push_val(env, CAR(CAR(item))); - eq(env); if(env->err) return; - + eqfunc(env); if(env->err) return; + + /* Check the result of 'eqfunc' */ + if(env->head->type==empty) { + printerr("Too Few Arguments"); + env->err= 1; + return; + } + if(CAR(env->head)->type!=integer) { + printerr("Bad Argument Type"); + env->err= 2; + return; + } + if(CAR(env->head)->content.i){ - toss(env); + toss(env); if(env->err) return; break; } - toss(env); + toss(env); if(env->err) return; + + if(item->type!=tcons) { + printerr("Bad Argument Type"); + env->err= 2; + return; + } + item=CDR(item); }