diff --git a/srfi/srfi-1.c b/srfi/srfi-1.c index 02f46fc..268f1dc 100644 --- a/srfi/srfi-1.c +++ b/srfi/srfi-1.c @@ -211,7 +211,7 @@ SCM_DEFINE (scm_srfi1_break, "break", 2, 0, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { SCM elem = SCM_CAR (lst); - if (scm_is_true (pred_tramp (pred, elem))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, elem))) goto done; /* want this elem, tack it onto the end of ret */ @@ -243,7 +243,7 @@ SCM_DEFINE (scm_srfi1_break_x, "break!", 2, 0, 0, p = &lst; for (upto = lst; scm_is_pair (upto); upto = SCM_CDR (upto)) { - if (scm_is_true (pred_tramp (pred, SCM_CAR (upto)))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, SCM_CAR (upto)))) goto done; /* want this element */ @@ -334,7 +334,8 @@ SCM_DEFINE (scm_srfi1_count, "count", 2, 0, 1, SCM_ASSERT (pred_tramp, pred, SCM_ARG1, FUNC_NAME); for ( ; scm_is_pair (list1); list1 = SCM_CDR (list1)) - count += scm_is_true (pred_tramp (pred, SCM_CAR (list1))); + count += scm_is_true_and_not_lisp_nil (pred_tramp (pred, + SCM_CAR (list1))); /* check below that list1 is a proper list, and done */ end_list1: @@ -361,8 +362,9 @@ SCM_DEFINE (scm_srfi1_count, "count", 2, 0, 1, argnum = 3; break; } - count += scm_is_true (pred_tramp - (pred, SCM_CAR (list1), SCM_CAR (list2))); + count += scm_is_true_and_not_lisp_nil (pred_tramp + (pred, SCM_CAR (list1), + SCM_CAR (list2))); list1 = SCM_CDR (list1); list2 = SCM_CDR (list2); } @@ -396,7 +398,8 @@ SCM_DEFINE (scm_srfi1_count, "count", 2, 0, 1, SCM_SIMPLE_VECTOR_SET (vec, i, SCM_CDR (lst)); /* rest of lst */ } - count += scm_is_true (scm_apply (pred, args, SCM_EOL)); + count += scm_is_true_and_not_lisp_nil (scm_apply (pred, args, + SCM_EOL)); } } @@ -452,7 +455,7 @@ SCM_DEFINE (scm_srfi1_delete, "delete", 2, 1, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { - if (scm_is_true (equal_p (pred, x, SCM_CAR (lst)))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, x, SCM_CAR (lst)))) { /* delete this element, so copy those at keeplst */ p = list_copy_part (keeplst, count, p); @@ -509,7 +512,7 @@ SCM_DEFINE (scm_srfi1_delete_x, "delete!", 2, 1, 0, scm_is_pair (walk); walk = SCM_CDR (walk)) { - if (scm_is_true (equal_p (pred, x, SCM_CAR (walk)))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, x, SCM_CAR (walk)))) *prev = SCM_CDR (walk); else prev = SCM_CDRLOC (walk); @@ -591,7 +594,7 @@ SCM_DEFINE (scm_srfi1_delete_duplicates, "delete-duplicates", 1, 1, 0, /* look for item in "ret" list */ for (l = ret; scm_is_pair (l); l = SCM_CDR (l)) { - if (scm_is_true (equal_p (pred, SCM_CAR (l), item))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, SCM_CAR (l), item))) { /* "item" is a duplicate, so copy keeplst onto ret */ duplicate: @@ -608,7 +611,7 @@ SCM_DEFINE (scm_srfi1_delete_duplicates, "delete-duplicates", 1, 1, 0, for (i = 0, l = keeplst; i < count && scm_is_pair (l); i++, l = SCM_CDR (l)) - if (scm_is_true (equal_p (pred, SCM_CAR (l), item))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, SCM_CAR (l), item))) goto duplicate; /* keep this element */ @@ -684,7 +687,8 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0, l = ret; for (;;) { - if (scm_is_true (equal_p (pred, SCM_CAR (l), item))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, SCM_CAR (l), + item))) break; /* equal, forget this element */ if (scm_is_eq (l, endret)) @@ -770,7 +774,7 @@ SCM_DEFINE (scm_srfi1_drop_while, "drop-while", 2, 0, 0, SCM_ASSERT (pred_tramp, pred, SCM_ARG1, FUNC_NAME); for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) - if (scm_is_false (pred_tramp (pred, SCM_CAR (lst)))) + if (scm_is_false_or_lisp_nil (pred_tramp (pred, SCM_CAR (lst)))) goto done; SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (lst), lst, SCM_ARG2, FUNC_NAME, "list"); @@ -824,7 +828,7 @@ SCM_DEFINE (scm_srfi1_filter_map, "filter-map", 2, 0, 1, for ( ; scm_is_pair (list1); list1 = SCM_CDR (list1)) { elem = proc_tramp (proc, SCM_CAR (list1)); - if (scm_is_true (elem)) + if (scm_is_true_and_not_lisp_nil (elem)) { newcell = scm_cons (elem, SCM_EOL); *loc = newcell; @@ -855,7 +859,7 @@ SCM_DEFINE (scm_srfi1_filter_map, "filter-map", 2, 0, 1, goto check_lst_and_done; } elem = proc_tramp (proc, SCM_CAR (list1), SCM_CAR (list2)); - if (scm_is_true (elem)) + if (scm_is_true_and_not_lisp_nil (elem)) { newcell = scm_cons (elem, SCM_EOL); *loc = newcell; @@ -895,7 +899,7 @@ SCM_DEFINE (scm_srfi1_filter_map, "filter-map", 2, 0, 1, } elem = scm_apply (proc, args, SCM_EOL); - if (scm_is_true (elem)) + if (scm_is_true_and_not_lisp_nil (elem)) { newcell = scm_cons (elem, SCM_EOL); *loc = newcell; @@ -924,7 +928,7 @@ SCM_DEFINE (scm_srfi1_find, "find", 2, 0, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { SCM elem = SCM_CAR (lst); - if (scm_is_true (pred_tramp (pred, elem))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, elem))) return elem; } SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (lst), lst, SCM_ARG2, FUNC_NAME, "list"); @@ -945,7 +949,7 @@ SCM_DEFINE (scm_srfi1_find_tail, "find-tail", 2, 0, 0, SCM_ASSERT (pred_tramp, pred, SCM_ARG1, FUNC_NAME); for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) - if (scm_is_true (pred_tramp (pred, SCM_CAR (lst)))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, SCM_CAR (lst)))) return lst; SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (lst), lst, SCM_ARG2, FUNC_NAME, "list"); @@ -1121,7 +1125,7 @@ SCM_DEFINE (scm_srfi1_list_index, "list-index", 2, 0, 1, SCM_ASSERT (pred_tramp, pred, SCM_ARG1, FUNC_NAME); for ( ; scm_is_pair (list1); n++, list1 = SCM_CDR (list1)) - if (scm_is_true (pred_tramp (pred, SCM_CAR (list1)))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, SCM_CAR (list1)))) return SCM_I_MAKINUM (n); /* not found, check below that list1 is a proper list */ @@ -1146,8 +1150,9 @@ SCM_DEFINE (scm_srfi1_list_index, "list-index", 2, 0, 1, argnum = 3; break; } - if (scm_is_true (pred_tramp (pred, - SCM_CAR (list1), SCM_CAR (list2)))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, + SCM_CAR (list1), + SCM_CAR (list2)))) return SCM_I_MAKINUM (n); list1 = SCM_CDR (list1); @@ -1183,7 +1188,7 @@ SCM_DEFINE (scm_srfi1_list_index, "list-index", 2, 0, 1, SCM_SIMPLE_VECTOR_SET (vec, i, SCM_CDR (lst)); /* rest of lst */ } - if (scm_is_true (scm_apply (pred, args, SCM_EOL))) + if (scm_is_true_and_not_lisp_nil (scm_apply (pred, args, SCM_EOL))) return SCM_I_MAKINUM (n); } } @@ -1286,7 +1291,8 @@ SCM_DEFINE (scm_srfi1_lset_adjoin, "lset-adjoin", 2, 0, 1, elem = SCM_CAR (rest); for (l = lst; scm_is_pair (l); l = SCM_CDR (l)) - if (scm_is_true (equal_tramp (equal, SCM_CAR (l), elem))) + if (scm_is_true_and_not_lisp_nil (equal_tramp (equal, SCM_CAR (l), + elem))) goto next_elem; /* elem already in lst, don't add */ SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P(l), lst, SCM_ARG2, FUNC_NAME, "list"); @@ -1343,7 +1349,8 @@ SCM_DEFINE (scm_srfi1_lset_difference_x, "lset-difference!", 2, 0, 1, r = SCM_CDR (r), argnum++) { for (b = SCM_CAR (r); scm_is_pair (b); b = SCM_CDR (b)) - if (scm_is_true (equal_tramp (equal, elem, SCM_CAR (b)))) + if (scm_is_true_and_not_lisp_nil (equal_tramp (equal, elem, + SCM_CAR (b)))) goto next_elem; /* equal to elem, so drop that elem */ SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (b), b, argnum, FUNC_NAME,"list"); @@ -1385,7 +1392,7 @@ check_map_args (SCM argv, long elt_len; elt = SCM_SIMPLE_VECTOR_REF (argv, i); - if (!(scm_is_null (elt) || scm_is_pair (elt))) + if (!(scm_is_null_or_lisp_nil (elt) || scm_is_pair (elt))) goto check_map_error; elt_len = srfi1_ilength (elt); @@ -1430,7 +1437,8 @@ scm_srfi1_map (SCM proc, SCM arg1, SCM args) SCM *pres = &res; len = srfi1_ilength (arg1); - SCM_GASSERTn ((scm_is_null (arg1) || scm_is_pair (arg1)) && len >= -1, + SCM_GASSERTn ((scm_is_null_or_lisp_nil (arg1) || + scm_is_pair (arg1)) && len >= -1, g_srfi1_map, scm_cons2 (proc, arg1, args), SCM_ARG2, s_srfi1_map); SCM_VALIDATE_REST_ARGUMENT (args); @@ -1456,7 +1464,7 @@ scm_srfi1_map (SCM proc, SCM arg1, SCM args) scm_cons2 (proc, arg1, args), SCM_ARG1, s_srfi1_map); if (len < 0 || (len2 >= 0 && len2 < len)) len = len2; - SCM_GASSERTn ((scm_is_null (arg2) || scm_is_pair (arg2)) + SCM_GASSERTn ((scm_is_null_or_lisp_nil (arg2) || scm_is_pair (arg2)) && len >= 0 && len2 >= -1, g_srfi1_map, scm_cons2 (proc, arg1, args), @@ -1501,7 +1509,8 @@ scm_srfi1_for_each (SCM proc, SCM arg1, SCM args) { long i, len; len = srfi1_ilength (arg1); - SCM_GASSERTn ((scm_is_null (arg1) || scm_is_pair (arg1)) && len >= -1, + SCM_GASSERTn ((scm_is_null_or_lisp_nil (arg1) || + scm_is_pair (arg1)) && len >= -1, g_srfi1_for_each, scm_cons2 (proc, arg1, args), SCM_ARG2, s_srfi1_for_each); SCM_VALIDATE_REST_ARGUMENT (args); @@ -1528,7 +1537,7 @@ scm_srfi1_for_each (SCM proc, SCM arg1, SCM args) scm_cons2 (proc, arg1, args), SCM_ARG1, s_srfi1_for_each); if (len < 0 || (len2 >= 0 && len2 < len)) len = len2; - SCM_GASSERTn ((scm_is_null (arg2) || scm_is_pair (arg2)) + SCM_GASSERTn ((scm_is_null_or_lisp_nil (arg2) || scm_is_pair (arg2)) && len >= 0 && len2 >= -1, g_srfi1_for_each, scm_cons2 (proc, arg1, args), @@ -1593,7 +1602,7 @@ SCM_DEFINE (scm_srfi1_member, "member", 2, 1, 0, } for (; !SCM_NULL_OR_NIL_P (lst); lst = SCM_CDR (lst)) { - if (scm_is_true (equal_p (pred, x, SCM_CAR (lst)))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, x, SCM_CAR (lst)))) return lst; } return SCM_BOOL_F; @@ -1621,7 +1630,7 @@ SCM_DEFINE (scm_srfi1_assoc, "assoc", 2, 1, 0, SCM tmp = SCM_CAR (ls); SCM_ASSERT_TYPE (scm_is_pair (tmp), alist, SCM_ARG2, FUNC_NAME, "association list"); - if (scm_is_true (equal_p (pred, key, SCM_CAR (tmp)))) + if (scm_is_true_and_not_lisp_nil (equal_p (pred, key, SCM_CAR (tmp)))) return tmp; } SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (ls), alist, SCM_ARG2, FUNC_NAME, @@ -1685,7 +1694,7 @@ SCM_DEFINE (scm_srfi1_partition, "partition", 2, 0, 0, elt = SCM_CAR (list); new_tail = scm_cons (SCM_CAR (list), SCM_EOL); - if (scm_is_true (call (pred, elt))) { + if (scm_is_true_and_not_lisp_nil (call (pred, elt))) { SCM_SETCDR(kept_tail, new_tail); kept_tail = new_tail; } @@ -1737,7 +1746,7 @@ SCM_DEFINE (scm_srfi1_partition_x, "partition!", 2, 0, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { - if (scm_is_true (pred_tramp (pred, SCM_CAR (lst)))) + if (scm_is_true_and_not_lisp_nil (pred_tramp (pred, SCM_CAR (lst)))) { *tp = lst; tp = SCM_CDRLOC (lst); @@ -1906,7 +1915,7 @@ SCM_DEFINE (scm_srfi1_remove, "remove", 2, 0, 0, scm_is_pair (walk); walk = SCM_CDR (walk)) { - if (scm_is_false (call (pred, SCM_CAR (walk)))) + if (scm_is_false_or_lisp_nil (call (pred, SCM_CAR (walk)))) { *prev = scm_cons (SCM_CAR (walk), SCM_EOL); prev = SCM_CDRLOC (*prev); @@ -1938,7 +1947,7 @@ SCM_DEFINE (scm_srfi1_remove_x, "remove!", 2, 0, 0, scm_is_pair (walk); walk = SCM_CDR (walk)) { - if (scm_is_false (call (pred, SCM_CAR (walk)))) + if (scm_is_false_or_lisp_nil (call (pred, SCM_CAR (walk)))) prev = SCM_CDRLOC (walk); else *prev = SCM_CDR (walk); @@ -1987,7 +1996,7 @@ SCM_DEFINE (scm_srfi1_span, "span", 2, 0, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { SCM elem = SCM_CAR (lst); - if (scm_is_false (pred_tramp (pred, elem))) + if (scm_is_false_or_lisp_nil (pred_tramp (pred, elem))) goto done; /* want this elem, tack it onto the end of ret */ @@ -2019,7 +2028,7 @@ SCM_DEFINE (scm_srfi1_span_x, "span!", 2, 0, 0, p = &lst; for (upto = lst; scm_is_pair (upto); upto = SCM_CDR (upto)) { - if (scm_is_false (pred_tramp (pred, SCM_CAR (upto)))) + if (scm_is_false_or_lisp_nil (pred_tramp (pred, SCM_CAR (upto)))) goto done; /* want this element */ @@ -2147,7 +2156,7 @@ SCM_DEFINE (scm_srfi1_take_while, "take-while", 2, 0, 0, for ( ; scm_is_pair (lst); lst = SCM_CDR (lst)) { SCM elem = SCM_CAR (lst); - if (scm_is_false (pred_tramp (pred, elem))) + if (scm_is_false_or_lisp_nil (pred_tramp (pred, elem))) goto done; /* want this elem, tack it onto the end of ret */ @@ -2178,7 +2187,7 @@ SCM_DEFINE (scm_srfi1_take_while_x, "take-while!", 2, 0, 0, p = &lst; for (upto = lst; scm_is_pair (upto); upto = SCM_CDR (upto)) { - if (scm_is_false (pred_tramp (pred, SCM_CAR (upto)))) + if (scm_is_false_or_lisp_nil (pred_tramp (pred, SCM_CAR (upto)))) goto done; /* want this element */