diff --git a/test/manual-suite.spt b/test/manual-suite.spt index b3edad2..3369a53 100644 --- a/test/manual-suite.spt +++ b/test/manual-suite.spt @@ -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") diff --git a/trans/chap8.str b/trans/chap8.str new file mode 100644 index 0000000..c239afc --- /dev/null +++ b/trans/chap8.str @@ -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(, Not()) + TermProj = ?Or(_, Not()) diff --git a/trans/spoofax_propositional_language.str b/trans/spoofax_propositional_language.str index 4ddeb43..a1ea266 100644 --- a/trans/spoofax_propositional_language.str +++ b/trans/spoofax_propositional_language.str @@ -15,6 +15,7 @@ imports prop-desugar chap6 chap7 + chap8 rules // Debugging