add pic_assoc

This commit is contained in:
Yuichi Nishiwaki 2013-12-07 06:30:21 -08:00
parent dcb5b448cd
commit aac2082991
2 changed files with 19 additions and 0 deletions

View File

@ -13,6 +13,7 @@ int pic_length(pic_state *, pic_value);
pic_value pic_reverse(pic_state *, pic_value);
pic_value pic_assq(pic_state *, pic_value key, pic_value assoc);
pic_value pic_assoc(pic_state *, pic_value key, pic_value assoc);
pic_value pic_acons(pic_state *, pic_value key, pic_value val, pic_value assoc);
pic_value pic_caar(pic_state *, pic_value);

View File

@ -128,6 +128,24 @@ pic_assq(pic_state *pic, pic_value key, pic_value assoc)
goto enter;
}
pic_value
pic_assoc(pic_state *pic, pic_value key, pic_value assoc)
{
pic_value cell;
enter:
if (pic_nil_p(assoc))
return assoc;
cell = pic_car(pic, assoc);
if (pic_equal_p(pic, key, pic_car(pic, cell)))
return cell;
assoc = pic_cdr(pic, assoc);
goto enter;
}
pic_value
pic_acons(pic_state *pic, pic_value key, pic_value val, pic_value assoc)
{