diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-12-27 17:15:35 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-12-27 17:15:35 -0800 |
commit | 6e0746c832be034d2e580e37c81f1f8a6952d23a (patch) | |
tree | ec8a57d2a0fac9671f4fb0a1345e254748e8839f /combi.c | |
parent | ca00aa3dc10a0d450106f0342a8506f5f416a5a0 (diff) | |
download | txr-6e0746c832be034d2e580e37c81f1f8a6952d23a.tar.gz txr-6e0746c832be034d2e580e37c81f1f8a6952d23a.tar.bz2 txr-6e0746c832be034d2e580e37c81f1f8a6952d23a.zip |
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.
Diffstat (limited to 'combi.c')
-rw-r--r-- | combi.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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); } } |