From 8ba1f04147d8f85e1a26fac2f91f91ecdad366d4 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 24 Nov 2014 15:08:01 -0500 Subject: [PATCH 01/12] Partial application initial development No support yet for recursive partial applications; just a basic concept. --- Makefile | 5 +- src/apply/partial.xsl | 85 ++++++++++++++ test/apply/partial-test.xsl | 43 +++++++ test/apply/partial.xspec | 202 +++++++++++++++++++++++++++++++++ test/transform/apply-gen.xspec | 4 +- 5 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 src/apply/partial.xsl create mode 100644 test/apply/partial-test.xsl create mode 100644 test/apply/partial.xspec diff --git a/Makefile b/Makefile index 4df9b82..ab7c49e 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,13 @@ path_src := src path_test := test -test_in_apply_gen := $(path_test)/transform/apply-gen-test-in.xsl.apply +test_apply := $(path_test)/apply/partial-test.xsl.apply \ + $(path_test)/transform/apply-gen-test-in.xsl.apply .PHONY: check test test: check -check: $(test_in_apply_gen) +check: $(test_apply) $(path_test)/runner %.apply: % diff --git a/src/apply/partial.xsl b/src/apply/partial.xsl new file mode 100644 index 0000000..14ad561 --- /dev/null +++ b/src/apply/partial.xsl @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/apply/partial-test.xsl b/test/apply/partial-test.xsl new file mode 100644 index 0000000..0695395 --- /dev/null +++ b/test/apply/partial-test.xsl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/test/apply/partial.xspec b/test/apply/partial.xspec new file mode 100644 index 0000000..8f0df53 --- /dev/null +++ b/test/apply/partial.xspec @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/transform/apply-gen.xspec b/test/transform/apply-gen.xspec index df9dae9..51de570 100644 --- a/test/transform/apply-gen.xspec +++ b/test/transform/apply-gen.xspec @@ -73,7 +73,7 @@ - " + @@ -187,7 +187,7 @@ - " + From a02865d8b14636a57e7678d4c883e8b5334c8844 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 24 Nov 2014 15:41:32 -0500 Subject: [PATCH 02/12] May now partially apply partial applications --- src/apply/partial.xsl | 20 ++++++++++++++++---- test/apply/partial.xspec | 21 +++++++++++++++++++++ tools/xspec | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/apply/partial.xsl b/src/apply/partial.xsl index 14ad561..ae59d9b 100644 --- a/src/apply/partial.xsl +++ b/src/apply/partial.xsl @@ -39,21 +39,33 @@ the dynamic function calls will handle currying/partial application for you, which has a much more inviting syntax. - TODO: Accept partial application as FNREF. + Partially applied functions may continue to be partially applied + until their parameters are exhausted. This can be used to implement + currying. --> - + + + + - + - + + + + diff --git a/test/apply/partial.xspec b/test/apply/partial.xspec index 8f0df53..e6e8c1e 100644 --- a/test/apply/partial.xspec +++ b/test/apply/partial.xspec @@ -94,6 +94,27 @@ + + + + + + + + + + + + + + + diff --git a/tools/xspec b/tools/xspec index 3dc0ab2..20c6b8a 160000 --- a/tools/xspec +++ b/tools/xspec @@ -1 +1 @@ -Subproject commit 3dc0ab2e1b78dae5d31c228c22a7dd8868d5678f +Subproject commit 20c6b8a32f37a6511698fe89b78b82fd1aa64bd2 From 04373b5eddf27eabd565f4a5cd1916826508cbec Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 25 Nov 2014 10:54:03 -0500 Subject: [PATCH 03/12] f:arity extracted into its own stylesheet It depends on partial application logic, but does not belong in partial.xsl --- src/apply.xsl | 18 ++--------- src/apply/arity.xsl | 48 +++++++++++++++++++++++++++++ test/apply.xspec | 39 ------------------------ test/apply/arity.xspec | 68 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 55 deletions(-) create mode 100644 src/apply/arity.xsl create mode 100644 test/apply/arity.xspec diff --git a/src/apply.xsl b/src/apply.xsl index d7fd6e3..5a2b704 100644 --- a/src/apply.xsl +++ b/src/apply.xsl @@ -30,6 +30,8 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://www.lovullo.com/hoxsl/apply"> + + @@ -193,20 +195,4 @@ - - - - - - - - diff --git a/src/apply/arity.xsl b/src/apply/arity.xsl new file mode 100644 index 0000000..5e9de23 --- /dev/null +++ b/src/apply/arity.xsl @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + diff --git a/test/apply.xspec b/test/apply.xspec index 8608775..90e644b 100644 --- a/test/apply.xspec +++ b/test/apply.xspec @@ -192,43 +192,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/apply/arity.xspec b/test/apply/arity.xspec new file mode 100644 index 0000000..bb94b01 --- /dev/null +++ b/test/apply/arity.xspec @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0dc019c9edec29f752f7d63b0db357baa6ab662e Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 25 Nov 2014 15:02:36 -0500 Subject: [PATCH 04/12] Error and hook for arity count in partial application --- src/apply/partial.xsl | 89 +++++++++++++++++++++++++++++++------ test/apply/partial-test.xsl | 15 +++++++ test/apply/partial.xspec | 81 ++++++++++++++++++++++++++------- 3 files changed, 155 insertions(+), 30 deletions(-) diff --git a/src/apply/partial.xsl b/src/apply/partial.xsl index ae59d9b..e94d904 100644 --- a/src/apply/partial.xsl +++ b/src/apply/partial.xsl @@ -28,6 +28,8 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://www.lovullo.com/hoxsl/apply"> + + - + @@ -53,22 +55,45 @@ as="element(f:ref)" select="$fnref[ 1 ]" /> - - + + + - + + + - - + - - + - - + + + + + + + + + + + + + + + + + + + + + @@ -94,4 +119,42 @@ and number( $fn/@partial ) gt 0" /> + + + + diff --git a/test/apply/partial-test.xsl b/test/apply/partial-test.xsl index 0695395..144d76b 100644 --- a/test/apply/partial-test.xsl +++ b/test/apply/partial-test.xsl @@ -33,6 +33,21 @@ + + + + diff --git a/test/apply/partial.xspec b/test/apply/partial.xspec index e6e8c1e..902cc2c 100644 --- a/test/apply/partial.xspec +++ b/test/apply/partial.xspec @@ -27,19 +27,20 @@ xmlns:foo="http://www.lovullo.com/_junk" stylesheet="partial-test.xsl"> - - + - - - - - - - + + + + + + + + + @@ -70,12 +71,8 @@ test="$x:result/@partial = 2" /> + test="$x:result[ 2 ] is $args/foo:a + and $x:result[ 3 ] is $args/foo:b" /> @@ -118,7 +115,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 465ef7e8a5c4017861dcdfcb2e6908d50399b435 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 26 Nov 2014 11:16:24 -0500 Subject: [PATCH 05/12] Apply test case ensures arguments are passed by reference Confidence in its application is also increased through a unique node. --- test/apply-test.xsl | 34 +++++---- test/apply.xspec | 164 ++++++++++++++++++++++++++------------------ 2 files changed, 118 insertions(+), 80 deletions(-) diff --git a/test/apply-test.xsl b/test/apply-test.xsl index 66cece9..5327deb 100644 --- a/test/apply-test.xsl +++ b/test/apply-test.xsl @@ -30,14 +30,15 @@ @@ -45,7 +46,8 @@ - + + @@ -54,7 +56,8 @@ - + + @@ -64,7 +67,8 @@ - + + @@ -75,8 +79,9 @@ - + + @@ -88,8 +93,9 @@ - + + @@ -102,8 +108,9 @@ - + + @@ -117,7 +124,8 @@ - + + diff --git a/test/apply.xspec b/test/apply.xspec index 90e644b..285268b 100644 --- a/test/apply.xspec +++ b/test/apply.xspec @@ -26,28 +26,21 @@ xmlns:foo="http://www.lovullo.com/_junk" stylesheet="apply-test.xsl"> + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + @@ -55,8 +48,9 @@ - + + " @@ -65,11 +59,12 @@ - + + test="$x:result[ 1 ] = foo:applied[ @n = 1 ] + and $x:result[ 2 ] is $args/foo:arg1" /> @@ -78,12 +73,14 @@ - - + + + test="$x:result[ 1 ] = foo:applied[ @n = 2 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2" /> @@ -92,13 +89,16 @@ - - - + + + + test="$x:result[ 1 ] = foo:applied[ @n = 3 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3" /> @@ -107,14 +107,18 @@ - - - - + + + + + test="$x:result[ 1 ] = foo:applied[ @n = 4 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3 + and $x:result[ 5 ] is $args/foo:arg4" /> @@ -123,15 +127,20 @@ - - - - - + + + + + + test="$x:result[ 1 ] = foo:applied[ @n = 5 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3 + and $x:result[ 5 ] is $args/foo:arg4 + and $x:result[ 6 ] is $args/foo:arg5" /> @@ -140,16 +149,22 @@ - - - - - - + + + + + + + test="$x:result[ 1 ] = foo:applied[ @n = 6 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3 + and $x:result[ 5 ] is $args/foo:arg4 + and $x:result[ 6 ] is $args/foo:arg5 + and $x:result[ 7 ] is $args/foo:arg6" /> @@ -158,17 +173,24 @@ - - - - - - - + + + + + + + + test="$x:result[ 1 ] = foo:applied[ @n = 7 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3 + and $x:result[ 5 ] is $args/foo:arg4 + and $x:result[ 6 ] is $args/foo:arg5 + and $x:result[ 7 ] is $args/foo:arg6 + and $x:result[ 8 ] is $args/foo:arg7" /> @@ -177,18 +199,26 @@ - - - - - - - - + + + + + + + + + test="$x:result[ 1 ] = foo:applied[ @n = 8 ] + and $x:result[ 2 ] is $args/foo:arg1 + and $x:result[ 3 ] is $args/foo:arg2 + and $x:result[ 4 ] is $args/foo:arg3 + and $x:result[ 5 ] is $args/foo:arg4 + and $x:result[ 6 ] is $args/foo:arg5 + and $x:result[ 7 ] is $args/foo:arg6 + and $x:result[ 8 ] is $args/foo:arg7 + and $x:result[ 9 ] is $args/foo:arg8" /> From b384e5fad1238a737078752fa9bac6cc327ea70a Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 26 Nov 2014 23:43:56 -0500 Subject: [PATCH 06/12] Partial applications apply target function when all params are bound I am aware of the Saxon 9 warning regarding multiple imports of arity.xsl; I'm going to choose to ignore this, formally in the future. Each of the stylesheets is treated like a module. Michael Kay, Saxon's author, discusses it here: http://stackoverflow.com/a/10102298 --- src/apply/partial.xsl | 50 ++++++- test/apply.xspec | 2 +- test/apply/partial-test.xsl | 4 + test/apply/partial.xspec | 259 ++++++++++++++++++++++++++++++++---- 4 files changed, 281 insertions(+), 34 deletions(-) diff --git a/src/apply/partial.xsl b/src/apply/partial.xsl index e94d904..2208a95 100644 --- a/src/apply/partial.xsl +++ b/src/apply/partial.xsl @@ -26,16 +26,18 @@ + xmlns:f="http://www.lovullo.com/hoxsl/apply" + xmlns:_f="http://www.lovullo.com/hoxsl/apply/_priv"> @@ -72,6 +78,10 @@ select="f:arity( $ref )" /> + + + + @@ -157,4 +167,36 @@ $argn, ' arguments' ) )" /> + + + + + + + + + + + + + + + + + + + + + diff --git a/test/apply.xspec b/test/apply.xspec index 285268b..4ccce28 100644 --- a/test/apply.xspec +++ b/test/apply.xspec @@ -50,7 +50,7 @@ " + test="$x:result[ 1 ] = foo:applied[ @n = 0 ]" /> diff --git a/test/apply/partial-test.xsl b/test/apply/partial-test.xsl index 144d76b..99dfadd 100644 --- a/test/apply/partial-test.xsl +++ b/test/apply/partial-test.xsl @@ -29,6 +29,9 @@ + + + @@ -53,6 +56,7 @@ + diff --git a/test/apply/partial.xspec b/test/apply/partial.xspec index 902cc2c..eda5a53 100644 --- a/test/apply/partial.xspec +++ b/test/apply/partial.xspec @@ -36,6 +36,10 @@ + + + + @@ -76,41 +80,252 @@ + - + - + - - + - + - - + + + test="count( $x:result ) = 3" /> + test="$x:result[ 2 ] is $args/foo:a + and $x:result[ 3 ] is $args/foo:b" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -202,20 +417,6 @@ - - - - - - - - - - From 33788871a9bc9cc9a4464dd24da17ef93d2b7732 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 26 Nov 2014 15:35:35 -0500 Subject: [PATCH 07/12] f:make-ref, f:is-ref, and f:QName added --- src/apply.xsl | 76 ++++++++++++++++++++- test/apply-test.xsl | 44 +++++++++--- test/apply.xspec | 161 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 10 deletions(-) diff --git a/src/apply.xsl b/src/apply.xsl index 5a2b704..f7130b5 100644 --- a/src/apply.xsl +++ b/src/apply.xsl @@ -1,4 +1,4 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/apply-test.xsl b/test/apply-test.xsl index 5327deb..010de9c 100644 --- a/test/apply-test.xsl +++ b/test/apply-test.xsl @@ -28,13 +28,25 @@ -