From 4ac284ddd4bbf4c3c02c0531795baf669bca4f54 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 19 Nov 2011 17:17:23 -0800 Subject: * match.c (v_deffilter): Even better. Just evaluate the arguments individually. Now @(deffilter a b ..) is possible where these evaluate to suitable lists of strings. * txr.1: Documented. --- ChangeLog | 9 +++++++++ match.c | 12 +----------- txr.1 | 15 +++++++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 353e258a..0f35be54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-11-19 Kaz Kylheku + + * match.c (v_deffilter): Even better. Just evaluate + the arguments individually. Now @(deffilter a b ..) + is possible where these evaluate to suitable + lists of strings. + + * txr.1: Documented. + 2011-11-19 Kaz Kylheku deffilter grows in power: it can take quasistrings. diff --git a/match.c b/match.c index 2b78cc8e..bb3da027 100644 --- a/match.c +++ b/match.c @@ -2899,18 +2899,8 @@ 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, 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); + val table_evaled = cdr(eval_form(specline, table, c->bindings)); if (!all_satisfy(table_evaled, andf(func_n1(listp), chain(func_n1(length), diff --git a/txr.1 b/txr.1 index cd30c208..f108639d 100644 --- a/txr.1 +++ b/txr.1 @@ -3564,10 +3564,10 @@ This directive's syntax is illustrated in this example: The deffilter symbol must be followed by the name of the filter to be defined, -followed by tuples of forms which evaluate to strings. Each tuple specifies one -or more texts which are mapped to a replacement text. For instance, the -following specifies a telephone keypad mapping from upper case letters to -digits. Quasiliterals may be used. +followed by forms which evaluate to lists of strings. Each list must +be at least two elements long and specifies one or more texts which are mapped +to a replacement text. For instance, the following specifies a telephone keypad +mapping from upper case letters to digits. @(deffilter alpha_to_phone ("E" "0") ("J" "N" "Q" "1") @@ -3582,6 +3582,13 @@ digits. Quasiliterals may be used. @(deffilter foo (`@a` `@b`) ("c" `->@d`)) + @(bind x ("from" "to")) + @(bind y ("---" "+++")) + @(deffilter sub x y) + +The last deffilter above equivalent to +@(deffilter sub ("from" "to") ("---" "+++")). + Filtering works using a longest match algorithm. The input is scanned from left to right, and the longest piece of text is identified at every character position which matches a string on the left hand side, and that text is -- cgit v1.2.3