feat: Implement chapter 8

This commit is contained in:
Glen Whitney 2021-01-20 19:35:07 -08:00
parent 98bb2088e4
commit fddc94a906
3 changed files with 50 additions and 1 deletions

View File

@ -169,7 +169,9 @@ The content and style of chapter 7 are similar to chapter 6. Again, there is a
`trans/chap7.str` Stratego file defining several of the rules used in the examples
from the chapter. As before, the examples with a different signature are recast
into the SPL signature. Specifically, `Z` becomes `False`, `S(x)` becomes
`Impl(True(), x)`, and `P` becomes `Or`.
`Impl(True(), x)`, and `P` becomes `Or`. (At least with these choices, all of the
transformations in the chapter remain valid in the usual semantics for the SPL
signature, even if a bit unorthodox.)
**/
test sec7_2_b_ex [[
@ -200,3 +202,37 @@ test sec7_3_repeat_big_ex [[
(1 -> (1 -> (1 -> (1 -> 0)))) | 0
]] run repeatmaybeAB to Impl(True(), Impl(True(), Impl(True(),
Impl(True(), False()))))
/** md
### Chapter 8
This chapter is even more just a collection of interactive examples. In this
repository we just give some examples of swapping and variable scope using the
SPL signature, and some free-form examples of term wrapping and projecting.
There's no attempt to do any of the arithmetic examples because SPL does not have
an integer type.
**/
test sec8_3_firstswap_ex [[
p | 0
]] run SwapWithPat to Or(False(), Atom("p"))
test sec8_3_1_swap_ex [[
p | 0
]] run SwapAnon to Or(False(), Atom("p"))
test sec8_3_2_variablescope_fails [[
p | 0
]] run NoSwapTwice fails
test sec8_3_2_localscope_ex [[
p | 0
]] run OkSwapTwice to Or(Atom("p"), False())
test sec8_5_1_wrap_ex [[
p
]] run TermWrap to Or(Atom("p"), Not(Atom("p")))
test sec8_5_2_project_ex [[
p | !p
]] run TermProj to Atom("p")

12
trans/chap8.str Normal file
View File

@ -0,0 +1,12 @@
module chap8
imports signatures/-
rules
SwapWithPat = ?Or(e1,e2); !Or(e2,e1)
SwapAnon = (Or(e1,e2) -> Or(e2,e1))
NoSwapTwice = (Or(e1,e2) -> Or(e2,e1)); (Or(e1,e2) -> Or(e2,e1))
OkSwapTwice =
{e3,e4 : (Or(e3,e4) -> Or(e4,e3))}; {e3,e4 : (Or(e3,e4) -> Or(e4,e3))}
TermWrap = !Or(<id>, Not(<id>))
TermProj = ?Or(_, Not(<id>))

View File

@ -15,6 +15,7 @@ imports
prop-desugar
chap6
chap7
chap8
rules // Debugging