From 1c6ee9d5990880f48fee51ac29c0a0dc9d733737 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 25 Jun 2019 07:39:56 -0700 Subject: drop-{while,until}: convert to seq_info. * lib.c (drop_while, drop_until): Use seq_info, so these functions work with all sequences. Thus now for instance [drop-while zerop #b'0000f00d'] yields #b'f00d'. --- lib.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index a28d90c5..b9cdeb8c 100644 --- a/lib.c +++ b/lib.c @@ -9601,25 +9601,25 @@ val drop(val count, val seq) val drop_while(val pred, val seq, val keyfun) { - switch (type(seq)) { - case NIL: + seq_info_t si = seq_info(seq); + + switch (si.kind) { + case SEQ_NIL: return nil; - case CONS: - case LCONS: + case SEQ_LISTLIKE: keyfun = default_arg(keyfun, identity_f); while (seq && funcall1(pred, funcall1(keyfun, car(seq)))) pop(&seq); return seq; - case LSTR: - case LIT: - case STR: - case VEC: + case SEQ_VECLIKE: { val pos = pos_if(notf(pred), seq, keyfun); if (!pos) return make_like(nil, seq); return sub(seq, pos, t); } + case SEQ_HASHLIKE: + type_mismatch(lit("drop-while: hashes not supported"), nao); default: type_mismatch(lit("drop-while: ~s is not a sequence"), seq, nao); } @@ -9627,11 +9627,12 @@ val drop_while(val pred, val seq, val keyfun) val drop_until(val pred, val seq, val keyfun) { - switch (type(seq)) { - case NIL: + seq_info_t si = seq_info(seq); + + switch (si.kind) { + case SEQ_NIL: return nil; - case CONS: - case LCONS: + case SEQ_LISTLIKE: { val key = default_arg(keyfun, identity_f); val item; @@ -9642,16 +9643,15 @@ val drop_until(val pred, val seq, val keyfun) return seq; } - case LSTR: - case LIT: - case STR: - case VEC: + case SEQ_VECLIKE: { val pos = pos_if(pred, seq, keyfun); if (!pos) return seq; return sub(seq, succ(pos), t); } + case SEQ_HASHLIKE: + type_mismatch(lit("drop-until: hashes not supported"), nao); default: type_mismatch(lit("drop-until: ~s is not a sequence"), seq, nao); } -- cgit v1.2.3