Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-01-29 13:19:15 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-09-11 09:30:53 -0400
commit46c230febb13cbe94b434b90cde4be3d68bd8a66 (patch)
treea223e18c3d83ec03c1058f6e3668080b34f606f7
parent34f7c6bef177c494cac6cad788b0ead326ee90fa (diff)
downloadtame-46c230febb13cbe94b434b90cde4be3d68bd8a66.tar.gz
tame-46c230febb13cbe94b434b90cde4be3d68bd8a66.tar.bz2
tame-46c230febb13cbe94b434b90cde4be3d68bd8a66.zip
_cons-until-empty_: Add @only@
* vector/list.xml (_cons-until-empty_): Add @only@, which has the opposite behavior to @glance@. (_merge-until-empty_): Proxy @only@.
-rw-r--r--core/vector/list.xml36
1 files changed, 29 insertions, 7 deletions
diff --git a/core/vector/list.xml b/core/vector/list.xml
index 8d3e9a6..eafbbdc 100644
--- a/core/vector/list.xml
+++ b/core/vector/list.xml
@@ -26,6 +26,7 @@
<import package="../base" />
<import package="../numeric/common" export="true" />
+ <import package="../when" export="true" />
@@ -49,6 +50,7 @@
<param name="@base@" desc="Base set to return (otherwise an empty set)" />
<param name="@glance@" desc="Glance at (but do nothing with) this value; recurse without action" />
+ <param name="@only@" desc="Process only this value; otherwise recurse without action" />
<!-- intended for use by merge-until-empty to reduce duplicate code; not to
be set via direct template applications -->
@@ -102,17 +104,35 @@
</c:values>
<!-- this case statement will be optimized away if we have no
- @glance@ value -->
+ @glance@ or @only@ value -->
<c:cases>
<!-- if we have a glancing value, then immediately recurse
without processing if we have a match -->
<if name="@glance@">
<c:case>
- <c:when name="@car@">
- <c:eq>
- <c:value-of name="@glance@" />
- </c:eq>
- </c:when>
+ <t:when-eq name="@car@" value="@glance@" />
+
+ <c:recurse>
+ <c:arg name="@set@">
+ <c:value-of name="@cdr@" />
+ </c:arg>
+
+ <if name="@index@">
+ <c:arg name="@index@">
+ <t:inc>
+ <c:value-of name="@index@" />
+ </t:inc>
+ </c:arg>
+ </if>
+ </c:recurse>
+ </c:case>
+ </if>
+
+ <!-- if we should only recurse when a value matches, ignore
+ non-match -->
+ <if name="@only@">
+ <c:case>
+ <t:when-ne name="@car@" value="@only@" />
<c:recurse>
<c:arg name="@set@">
@@ -206,9 +226,11 @@
</param>
<param name="@glance@" desc="Glance at (but do nothing with) this value; recurse without action" />
+ <param name="@only@" desc="Process only this value; otherwise recurse without action" />
<!-- to reduce duplicate template code, we simply set a merge flag on cons-until-empty -->
- <t:cons-until-empty set="@set@" car="@car@" cdr="@cdr@" glance="@glance@" merge="true">
+ <t:cons-until-empty set="@set@" car="@car@" cdr="@cdr@"
+ glance="@glance@" only="@only@" merge="true">
<param-copy name="@values@" />
</t:cons-until-empty>
</template>