Sorry, I guess that wasn't very clear. Let's put a really simple
example with just the pattern-matching subset:
strucjure.regression.sandbox=> (def p (pattern [1 ^x _ 3]))
#'strucjure.regression.sandbox/p
strucjure.regression.sandbox=> p
[1 #strucjure.pattern.Bind{:symbol x, :pattern #strucjure.pattern.Any{}} 3]
strucjure.regression.sandbox=> (def o (output ~p (fnk [x] x)))
#'strucjure.regression.sandbox/o
strucjure.regression.sandbox=> o
#strucjure.pattern.Output{:pattern [1 #strucjure.pattern.Bind{:symbol
x, :pattern #strucjure.pattern.Any{}} 3], :fnk #<
clojure.lang.AFunction$1@18ab1e1c>}
strucjure.regression.sandbox=> ((view ~p) [1 2 3])
[[1 2 3] nil]
strucjure.regression.sandbox=> ((view ~o) [1 2 3])
[2 nil]
strucjure.regression.sandbox=> (pprint (macroexpand-1 '(view ~o)))
(fn
[input3910]
(clojure.core/when
(clojure.core/vector? input3910)
(clojure.core/when
(clojure.core/>= (clojure.core/count input3910) 3)
(clojure.core/let
[input-sym3911 (clojure.core/nth input3910 0)]
(clojure.core/when
(clojure.core/= input-sym3911 '1)
(clojure.core/let
[input-sym3912 (clojure.core/nth input3910 1)]
(clojure.core/let
[x input-sym3912]
(clojure.core/let
[input-sym3913 (clojure.core/nth input3910 2)]
(clojure.core/when
(clojure.core/= input-sym3913 '3)
[(#<sandbox$fn__3090$pos_fn__1649__auto____3091
strucjure.regression.sandbox$fn__3090$pos_fn__1649__auto____3091@62b1f96f>
x)
(clojure.core/seq (clojure.core/subvec input3910 3))])))))))))
You can see towards the end of the generated code where it calls the
fnk directly as #<sandbox$fn__3090...>
The motivation here is that you can define the grammar for a language
once and then make different transformations by attaching output fnks.
It would be very useful if those output fnks could be closures.
It's not obvious in this small example but the compiler produces some
important optimisations, otherwise I could just interpret the grammar
and there would be no problem.
In general, for staged programming it's useful to be able to pass
arbitrary data between stages eg metaocaml
(
http://okmij.org/ftp/ML/MetaOCaml.html) often passes refs between
stages. I think some of the terra (
http://terralang.org/) examples
pass closures too.