2451 |
/* 1: [ [ 1 . 2 ] [ 3 . 4 ] ] => 1: [ 3 . 4 ] */ |
/* 1: [ [ 1 . 2 ] [ 3 . 4 ] ] => 1: [ 3 . 4 ] */ |
2452 |
extern void assq(environment *env) |
extern void assq(environment *env) |
2453 |
{ |
{ |
2454 |
|
assocgen(env, eq); |
2455 |
|
} |
2456 |
|
|
2457 |
|
|
2458 |
|
/* General assoc function */ |
2459 |
|
void assocgen(environment *env, funcp eqfunc) |
2460 |
|
{ |
2461 |
value *key, *item; |
value *key, *item; |
2462 |
|
|
2463 |
/* Needs two values on the stack, the top one must be an association |
/* Needs two values on the stack, the top one must be an association |
2485 |
} |
} |
2486 |
push_val(env, key); |
push_val(env, key); |
2487 |
push_val(env, CAR(CAR(item))); |
push_val(env, CAR(CAR(item))); |
2488 |
eq(env); if(env->err) return; |
eqfunc(env); if(env->err) return; |
2489 |
|
|
2490 |
|
/* Check the result of 'eqfunc' */ |
2491 |
|
if(env->head->type==empty) { |
2492 |
|
printerr("Too Few Arguments"); |
2493 |
|
env->err= 1; |
2494 |
|
return; |
2495 |
|
} |
2496 |
|
if(CAR(env->head)->type!=integer) { |
2497 |
|
printerr("Bad Argument Type"); |
2498 |
|
env->err= 2; |
2499 |
|
return; |
2500 |
|
} |
2501 |
|
|
2502 |
if(CAR(env->head)->content.i){ |
if(CAR(env->head)->content.i){ |
2503 |
toss(env); |
toss(env); if(env->err) return; |
2504 |
break; |
break; |
2505 |
} |
} |
2506 |
toss(env); |
toss(env); if(env->err) return; |
2507 |
|
|
2508 |
|
if(item->type!=tcons) { |
2509 |
|
printerr("Bad Argument Type"); |
2510 |
|
env->err= 2; |
2511 |
|
return; |
2512 |
|
} |
2513 |
|
|
2514 |
item=CDR(item); |
item=CDR(item); |
2515 |
} |
} |
2516 |
|
|