1
1
# Symmetric Meta Programming
2
2
3
3
Symmetric meta programming is a new framework for staging and for some
4
- forms of macros. It is is expressed as strongly and statically typed
4
+ forms of macros. It 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
7
regulated by a phase consistency principle that treats quotes and
@@ -90,7 +90,7 @@ allowed everywhere.
90
90
The phase consistency principle can be motivated as follows: First,
91
91
suppose the result of a program ` P ` is some quoted text `’{ ... x
92
92
... }` that refers to a free variable ` x` in ` P` This can be
93
- represented only by referring to original the variable ` x ` . Hence, the
93
+ represented only by referring to the original variable ` x ` . Hence, the
94
94
result of the program will need to persist the program state itself as
95
95
one of its parts. We don’t want to do this, hence this situation
96
96
should be made illegal. Dually, suppose a top-level part of a program
@@ -180,7 +180,7 @@ Here’s the definition of the `mapImpl` macro, which takes quoted types and exp
180
180
181
181
object Macros {
182
182
183
- def mapImpl[T, U](u: Type[U], arr: Expr[Array[T]], op: Expr[T => U])(implicit ctx: Context) : Expr[Array[U]] = ’{
183
+ def mapImpl[T, U](u: Type[U], arr: Expr[Array[T]], op: Expr[T => U]): Expr[Array[U]] = ’{
184
184
var i = 0
185
185
val xs = ~arr
186
186
var len = xs.length
@@ -314,7 +314,7 @@ tweak of the typing rules. An inline function such as `assert` that
314
314
contains a splice operation outside an enclosing quote is called a
315
315
_ macro_ . Macros are supposed to be expanded in a subsequent phase,
316
316
i.e. in a quoted context. Therefore, they are also type checked as if
317
- they were in a quoted context, For instance, the definition of
317
+ they were in a quoted context. For instance, the definition of
318
318
` assert ` is typechecked as if it appeared inside quotes. This makes
319
319
the call from ` assert ` to ` assertImpl ` phase-correct, even if we
320
320
assume that both definitions are local.
@@ -631,9 +631,9 @@ We define a small step reduction relation `-->` with the following rules:
631
631
632
632
~(’t) --> t
633
633
634
- t --> t’
635
- ----------------
636
- e[t ] --> e[t’ ]
634
+ t1 --> t2
635
+ - ----------------
636
+ e[t1 ] --> e[t2 ]
637
637
638
638
The first rule is standard call-by-value beta-reduction. The second
639
639
rule says that splice and quotes cancel each other out. The third rule
@@ -668,14 +668,14 @@ environment of the stack.
668
668
Es * E |- x: T
669
669
670
670
671
- Es * E, x: T |- t: T’
672
- ------------------------------
673
- Es * E |- (x: T ) => t: T -> T’
671
+ Es * E, x: T1 |- t: T2
672
+ -------------------------------
673
+ Es * E |- (x: T1 ) => t: T -> T2
674
674
675
675
676
- Es |- t: T’ -> T Es |- t’: T’
677
- --------------------------------
678
- Es |- t t’ : T
676
+ Es |- t1: T2 -> T Es |- t2: T2
677
+ ---------------------------------
678
+ Es |- t1 t2 : T
679
679
680
680
The rules for quotes and splices map between ` expr T ` and ` T ` by trading ` ’ ` and ` ~ ` between
681
681
environments and terms.
@@ -743,7 +743,7 @@ constructor could be typed as follows:
743
743
744
744
This would allow constructing applications from lists of arguments
745
745
without having to match the arguments one-by-one with the
746
- corresponding formal parameter types of the function. We need then "at
746
+ corresponding formal parameter types of the function. We then need "at
747
747
the end" a method to convert an ` Expr[_] ` to an ` Expr[T] ` where ` T ` is
748
748
given from the outside. E.g. if ` code ` yields a ` Expr[_] ` , then
749
749
` code.atType[T] ` yields an ` Expr[T] ` . The ` atType ` method has to be
@@ -757,7 +757,7 @@ to be type correct loses a lot of guidance for constructing the right
757
757
trees. So we should wait with this addition until we have more
758
758
use-cases that help us decide whether the loss in type-safety is worth
759
759
the gain in flexibility. In this context, it seems that deconstructing types is
760
- less error-prone than deconstructing tersm , so one might also
760
+ less error-prone than deconstructing terms , so one might also
761
761
envisage a solution that allows the former but not the latter.
762
762
763
763
## Conclusion
0 commit comments