From 1f3d894dab47e0d2527adf7db0b74296f19f7b81 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 19 Nov 2011 12:05:39 -0800 Subject: 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. --- match.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'match.c') diff --git a/match.c b/match.c index f5d23760..2b78cc8e 100644 --- a/match.c +++ b/match.c @@ -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; } -- cgit v1.2.3