From 6e0746c832be034d2e580e37c81f1f8a6952d23a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 27 Dec 2023 17:15:35 -0800 Subject: comb: support general sequences. * combi.c (comb_seq_gen_fun, comb_seq): New static functions. (comb): Call comb_seq in default case rather than throwing error. --- combi.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/combi.c b/combi.c index 79f65f2a..986ea38d 100644 --- a/combi.c +++ b/combi.c @@ -527,6 +527,21 @@ static val comb_hash(val hash, val k) func_f0(hstate, comb_hash_gen_fun)); } +static val comb_seq_gen_fun(val sstate) +{ + cons_bind (state, seq, sstate); + val list = comb_list_gen_fun(state); + return make_like(list, seq); +} + +static val comb_seq(val seq, val k) +{ + val state = comb_init(list_seq(seq), k); + val sstate = cons(state, seq); + return generate(func_f0(state, comb_while_fun), + func_f0(sstate, comb_seq_gen_fun)); +} + val comb(val seq, val k) { if (!integerp(k)) @@ -565,7 +580,7 @@ val comb(val seq, val k) return nil; return comb_hash(seq, k); } - type_mismatch(lit("comb: ~s is not a sequence"), seq, nao); + return comb_seq(seq, k); } } -- cgit v1.2.3