@@ -4,8 +4,8 @@ Symmetric meta programming is a new framework for staging and for some
4
4
forms of macros. It is is expressed as strongly and statically typed
5
5
code using two fundamental operations: quotations and splicing. A
6
6
novel aspect of the approach is that these two operations are
7
- regulated by a phase consistency principle that treats splices and
8
- quotes in exactly the same way.
7
+ regulated by a phase consistency principle that treats quotes and
8
+ splices in exactly the same way.
9
9
10
10
## Overview
11
11
@@ -104,8 +104,8 @@ create nor remove quotes or splices individually. So the PCP ensures
104
104
that program elaboration will lead to neither of the two unwanted
105
105
situations described above.
106
106
107
- In the the range of features it covers, symmetric meta programming is
108
- quite close to the MetaML family. One difference is that MetaML does
107
+ In what concerns the range of features it covers, symmetric meta programming is
108
+ quite close to the MetaML family of languages . One difference is that MetaML does
109
109
not have an equivalent of the PCP - quoted code in MetaML _ can_ access
110
110
variables in its immediately enclosing environment, with some
111
111
restrictions and caveats since such accesses involve serialization.
@@ -456,7 +456,7 @@ is defined in the companion object of class `Expr` as follows:
456
456
The conversion says that values of types implementing the ` Liftable `
457
457
type class can be converted ("lifted") automatically to ` Expr `
458
458
values. Dotty comes with instance definitions of ` Liftable ` for
459
- several types including all underlying types of literals. For instance
459
+ several types including all underlying types of literals. For example,
460
460
` Int ` values can be converted to ` Expr[Int] ` values by wrapping the
461
461
value in a ` Literal ` tree node. This makes use of the underlying tree
462
462
representation in the compiler for efficiency. But the ` Liftable `
@@ -592,9 +592,7 @@ combinators `’` and `~`.
592
592
~
593
593
594
594
The two environment combinators are both associative with left and
595
- right identity ` () ` . The initial environment contains among other
596
- predefined operations also a "run" operation ` ! : expr T => T ` . That
597
- is, ` ! ` is treated just like any other function.
595
+ right identity ` () ` .
598
596
599
597
### Operational semantics:
600
598
@@ -617,6 +615,14 @@ splice evaluation context `e_s` are defined syntactically as follows:
617
615
Eval context e ::= [ ] | e t | v e | ’e_s[~e]
618
616
Splice context e_s ::= [ ] | (x: T) => e_s | e_s t | q e_s
619
617
618
+ A _ run_ operation can be added to the calculus by adding a binding
619
+ ` run : expr T -> T ` to the initial environment, together with the evaluation rule
620
+
621
+ run('t) --> t
622
+
623
+ That is, ` run ` reduces in the same way as ` ~ ` when in evaluation position. But unlike splices,
624
+ ` run ` operations are only evaluated outside of quotes, which means they are not affected by the PCP.
625
+
620
626
### Typing rules
621
627
622
628
Typing judgments are of the form ` Es |- t: T ` . There are two
@@ -650,7 +656,6 @@ environment of the stack.
650
656
--------------------------------
651
657
Es |- t t’: T
652
658
653
-
654
659
The rules for quotes and splices map between ` expr T ` and ` T ` by trading ` ’ ` and ` ~ ` between
655
660
environments and terms.
656
661
@@ -736,12 +741,10 @@ envisage a solution that allows the former but not the latter.
736
741
737
742
## Conclusion
738
743
739
- Meta-programming always made my head hurt (I believe that’s the same
740
- for many people). But with explicit ` Expr/Type ` types and quotes and
741
- splices it has become downright pleasant. The method I was following
742
- was to first define the underlying quoted or unquoted types using
743
- ` Expr ` and ` Type ` and then insert quotes and splices to make the types
744
- line up. Phase consistency was at the same time a great guideline
745
- where to insert a splice or a quote and a vital sanity check that I
746
- did the right thing.
747
-
744
+ Meta-programming has a reputation of being difficult and confusing.
745
+ But with explicit ` Expr/Type ` types and quotes and splices it can become
746
+ downright pleasant. A simple strategy first defines the underlying quoted or unquoted
747
+ values using ` Expr ` and ` Type ` and then inserts quotes and splices to make the types
748
+ line up. Phase consistency is at the same time a great guideline
749
+ where to insert a splice or a quote and a vital sanity check that
750
+ the result makes sense.
0 commit comments