summaryrefslogtreecommitdiff
path: root/srfi/srfi-1.c
diff options
context:
space:
mode:
authorMikael Djurfeldt <djurfeldt@nada.kth.se>2002-12-01 13:56:11 +0000
committerMikael Djurfeldt <djurfeldt@nada.kth.se>2002-12-01 13:56:11 +0000
commit7692d26b31818fbc8fedf27f00decb5a4c5468f8 (patch)
tree4cd060fdc7c497dced07f8154f31060d3b4ea3be /srfi/srfi-1.c
parentee6aac97334d5eb24ccdfbcfd1a49f9e28492e73 (diff)
downloadguile-7692d26b31818fbc8fedf27f00decb5a4c5468f8.tar.gz
* srfi-1.scm: Load srfi-1 extension.
(map, map-in-order, for-each, member, assoc): Replaced by primitives in srfi-1.c. (map1): Defined as `map'.
Diffstat (limited to 'srfi/srfi-1.c')
-rw-r--r--srfi/srfi-1.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/srfi/srfi-1.c b/srfi/srfi-1.c
index 8783e8384..35e9bc389 100644
--- a/srfi/srfi-1.c
+++ b/srfi/srfi-1.c
@@ -288,11 +288,13 @@ equal_trampoline (SCM proc, SCM arg1, SCM arg2)
SCM_DEFINE (scm_srfi1_member, "member", 2, 1, 0,
(SCM x, SCM lst, SCM pred),
"Return the first sublist of @var{lst} whose car is\n"
- "@code{equal?} to @var{x} where the sublists of @var{lst} are\n"
+ "@var{equal?} to @var{x} where the sublists of @var{lst} are\n"
"the non-empty lists returned by @code{(list-tail @var{lst}\n"
"@var{k})} for @var{k} less than the length of @var{lst}. If\n"
"@var{x} does not occur in @var{lst}, then @code{#f} (not the\n"
- "empty list) is returned.")
+ "empty list) is returned. If optional third argument @var{equal?}\n"
+ "isn't given, @code{equal?} is used for comparison.\n"
+ "(Extended from R5RS.)\n")
#define FUNC_NAME s_scm_srfi1_member
{
scm_t_trampoline_2 equal_p;
@@ -313,6 +315,36 @@ SCM_DEFINE (scm_srfi1_member, "member", 2, 1, 0,
}
#undef FUNC_NAME
+SCM_DEFINE (scm_srfi1_assoc, "assoc", 2, 1, 0,
+ (SCM key, SCM alist, SCM pred),
+ "Behaves like @code{assq} but uses third argument @var{pred?}\n"
+ "for key comparison. If @var{pred?} is not supplied,\n"
+ "@code{equal?} is used. (Extended from R5RS.)\n")
+#define FUNC_NAME s_scm_srfi1_assoc
+{
+ SCM ls = alist;
+ scm_t_trampoline_2 equal_p;
+ if (SCM_UNBNDP (pred))
+ equal_p = equal_trampoline;
+ else
+ {
+ equal_p = scm_trampoline_2 (pred);
+ SCM_ASSERT (equal_p, pred, 3, FUNC_NAME);
+ }
+ for(; SCM_CONSP (ls); ls = SCM_CDR (ls))
+ {
+ SCM tmp = SCM_CAR (ls);
+ SCM_ASSERT_TYPE (SCM_CONSP (tmp), alist, SCM_ARG2, FUNC_NAME,
+ "association list");
+ if (SCM_NFALSEP (equal_p (pred, SCM_CAR (tmp), key)))
+ return tmp;
+ }
+ SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (ls), alist, SCM_ARG2, FUNC_NAME,
+ "association list");
+ return SCM_BOOL_F;
+}
+#undef FUNC_NAME
+
void
scm_init_srfi_1 (void)
{