diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-19 12:05:39 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-19 12:05:39 -0800 |
commit | 1f3d894dab47e0d2527adf7db0b74296f19f7b81 (patch) | |
tree | c1f427b2c9d03760e1563ae53302359b7dc3cdb4 /match.c | |
parent | d3ba0368d9c5012ca9405ac55a6d9a632fb0895a (diff) | |
download | txr-1f3d894dab47e0d2527adf7db0b74296f19f7b81.tar.gz txr-1f3d894dab47e0d2527adf7db0b74296f19f7b81.tar.bz2 txr-1f3d894dab47e0d2527adf7db0b74296f19f7b81.zip |
deffilter grows in power: it can take quasistrings.
* lib.c (cdr_f): New global variable.
(funcall1, funcall2, funcall3, funcall4): Fix unterminated
arguments in uw_throwf call by using uw_throw instead.
(do_or): New static function.
(orf): New function.
(obj_init): gc_protect and initialize cdr_f.
* lib.h (cdr_f, orf): Declared.
* match.c (v_deffilter): Treat the table as forms to be evaluated which
must reduce to strings, rather than literal strings.
* txr.1: Documented.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 37 |
1 files changed, 28 insertions, 9 deletions
@@ -2899,18 +2899,37 @@ static val v_deffilter(match_files_ctx *c) sem_error(specline, lit("deffilter: ~a is not a symbol"), first(first_spec), nao); - if (!all_satisfy(table, andf(func_n1(listp), - chain(func_n1(length), - curry_12_1(func_n2(ge), two), nao), - chain(func_n1(rest), - curry_123_1(func_n3(all_satisfy), - func_n1(stringp), nil), nao), - nao), - nil)) + if (!all_satisfy(table, func_n1(listp), nil)) + sem_error(specline, + lit("deffilter arguments must be lists"), + nao); + + { + val table_evaled = mapcar(curry_12_2(func_n2(mapcar), + chain(curry_123_2(func_n3(eval_form), + specline, c->bindings), + cdr_f, + nao)), + table); + + if (!all_satisfy(table_evaled, andf(func_n1(listp), + chain(func_n1(length), + curry_12_1(func_n2(ge), two), nao), + chain(func_n1(rest), + curry_123_1(func_n3(all_satisfy), + func_n1(stringp), + nil), + nao), + nao), + nil)) sem_error(specline, lit("deffilter arguments must be lists of at least two strings"), nao); - register_filter(sym, table); + + register_filter(sym, table_evaled); + } + + /* TODO: warn about replaced filter. */ return next_spec_k; } |