From e680fcaaa59d181af0356d7446ca1e5628598215 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 20 Nov 2014 19:08:22 -0800 Subject: * lib.c (sel): Accept a function in place of the index list. * txr.1: Documented. --- ChangeLog | 6 ++++++ lib.c | 4 +++- txr.1 | 15 ++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80681bd7..720e9371 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-11-20 Kaz Kylheku + + * lib.c (sel): Accept a function in place of the index list. + + * txr.1: Documented. + 2014-11-17 Kaz Kylheku * lib.c (split_str): If the separator string is empty, diff --git a/lib.c b/lib.c index 796a126c..c4e6395f 100644 --- a/lib.c +++ b/lib.c @@ -6209,7 +6209,9 @@ val sel(val seq_in, val where_in) { list_collect_decl (out, ptail); val seq = nullify(seq_in); - val where = nullify(where_in); + val where = if3(functionp(where_in), + funcall1(where_in, seq), + nullify(where_in)); switch (type(seq)) { case NIL: diff --git a/txr.1 b/txr.1 index 74e542f4..7b4d85fe 100644 --- a/txr.1 +++ b/txr.1 @@ -13312,7 +13312,7 @@ that element is added to a list. Finally, the list is returned. .coNP Function @ select .synb -.mets (select < object << index-list ) +.mets (select < object >> { index-list <> | function }) .syne .desc @@ -13326,6 +13326,19 @@ which are identified by the indices in .metn index-list . +If +.meta function +is given instead of +.metn index-list , +then +.meta function +is invoked with +.meta object +as its argument. The return value is then taken as +if it were the +.meta index-list +argument . + If .meta object is a sequence, then -- cgit v1.2.3