Skip to content

Commit 07bbb2b

Browse files
committed
More doc fixes
1 parent 5fe6d15 commit 07bbb2b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

docs/docs/reference/symmetric-meta-programming.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Symmetric meta programming is a new framework for staging and for some
44
forms of macros. It is is expressed as strongly and statically typed
55
code using two fundamental operations: quotations and splicing. A
66
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.
99

1010
## Overview
1111

@@ -104,8 +104,8 @@ create nor remove quotes or splices individually. So the PCP ensures
104104
that program elaboration will lead to neither of the two unwanted
105105
situations described above.
106106

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
109109
not have an equivalent of the PCP - quoted code in MetaML _can_ access
110110
variables in its immediately enclosing environment, with some
111111
restrictions and caveats since such accesses involve serialization.
@@ -456,7 +456,7 @@ is defined in the companion object of class `Expr` as follows:
456456
The conversion says that values of types implementing the `Liftable`
457457
type class can be converted ("lifted") automatically to `Expr`
458458
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,
460460
`Int` values can be converted to `Expr[Int]` values by wrapping the
461461
value in a `Literal` tree node. This makes use of the underlying tree
462462
representation in the compiler for efficiency. But the `Liftable`
@@ -592,9 +592,7 @@ combinators `’` and `~`.
592592
~
593593

594594
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 `()`.
598596

599597
### Operational semantics:
600598

@@ -617,6 +615,14 @@ splice evaluation context `e_s` are defined syntactically as follows:
617615
Eval context e ::= [ ] | e t | v e | ’e_s[~e]
618616
Splice context e_s ::= [ ] | (x: T) => e_s | e_s t | q e_s
619617

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+
620626
### Typing rules
621627

622628
Typing judgments are of the form `Es |- t: T`. There are two
@@ -650,7 +656,6 @@ environment of the stack.
650656
--------------------------------
651657
Es |- t t’: T
652658

653-
654659
The rules for quotes and splices map between `expr T` and `T` by trading `` and `~` between
655660
environments and terms.
656661

@@ -736,12 +741,10 @@ envisage a solution that allows the former but not the latter.
736741

737742
## Conclusion
738743

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

Comments
 (0)