urbit/j/2/scag.c
2014-11-04 16:53:07 -08:00

53 lines
827 B
C

/* j/2/scag.c
**
** This file is in the public domain.
*/
#include "all.h"
/* functions
*/
u3_noun
u3_cqb_scag(
u3_atom a,
u3_noun b)
{
if ( u3_ne(u3_ca_is_cat(a)) ) {
return u3_cm_bail(c3__fail);
}
else {
u3_noun acc;
c3_w i_w = a;
if ( !i_w )
return u3_nul;
while ( i_w ) {
if ( u3_no == u3du(b) ) {
return u3_nul;
}
acc = u3_ci_cell( u3h(b), acc );
b = u3t(b);
i_w--;
}
return u3_ckb_flop(acc);
}
}
u3_noun
u3_cwb_scag(
u3_noun cor)
{
u3_noun a, b;
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &a, u3_cv_sam_3, &b, 0)) ||
(u3_no == u3ud(a)) )
{
return u3_cm_bail(c3__exit);
} else {
return u3_cqb_scag(a, b);
}
}