modal/examples/tests.modal

96 lines
1.9 KiB
Plaintext

?(?-) (This example tests various aspects of the implementation.)
<> (ghost) ()
?(?-) (Whitespace)
(a b c ) = (a b c) test
( a b c) = (a b c) test
( a b c ) = (a b c) test
(a b c ( a b c ) ) = (a b c (a b c)) test
?(?-) (Inline rules)
<> ((?x -> ?y)) (<> ?x ?y)
(nap -> (tap =))
nap tap test
?(?-) (Empty replacements)
(ab cd () ghost) = (ab cd ()) test
(ab cd ghost ()) = (ab cd ()) test
(ab ghost cd ()) = (ab cd ()) test
(ghost ab cd ()) = (ab cd ()) test
(ghost) = () test
(q ?((?x ?y ?z) (?x ?y)) a b c) = (q a b) test
(q ?((?x ?y ?z) (?x ?z)) a b c) = (q a c) test
(q ?((?x ?y ?z) (?y ?z)) a b c) = (q b c) test
<> (prefix/pop ?x) ()
<> (?x suffix/pop) ()
(prefix/pop foo) = (ok) test
(foo suffix/pop) = (ok) test
?(?-) (Basic replacements)
<> (replace-name (foo)) ((bar) =)
replace-name (foo) (bar) test
?(?-) (Basic register setups)
<> (dup (?x)) (?x ?x)
<> (swap (?x ?y)) (?y ?x)
<> (compare (?x ?x ?x)) (#t)
<> (rotate (?x (?y (?z)))) (?y (?z (?x)))
(dup (abc)) = (abc abc) test
(swap (abc def)) = (def abc) test
compare (abc abc abc) = #t test
(rotate (abc (def (ghi)))) = (def (ghi (abc))) test
?(?-) (Empty register replacement)
<> (replace-empty ?x) (?y)
replace-empty abc = ?y test
?(?-) (Substring registers)
<> (connect ?x ?y ?z) (?x-?y?z)
<> (prefix-?x) (?x-suffix)
connect foo bar baz = foo-barbaz test
prefix-anything = anything-suffix test
?(?-) (Lambdas)
?(?x (?x ?x)) abc = (abc abc) test
abc ?(?x) def = abc test
?(?-) (Explode)
?(?* ?*) cow = (c (o (w ()))) test
?(?* ?*) (12 34 45) = (12 (34 (45 ()))) test
?(?-) (op: join)
?(?^ ?^) (b (a (t ()))) = bat test
?(?^ ?^) (12 (34 (56 ()))) = 123456 test
?(?-) (Test Primitives)
<> (?: print) (?:)
<> (?x = ?x test) (#ok\n print)
<> (?x = ?y test) (#fail\n print)
?(?-) (List reversal)
<> (reverse List () ?^) (?^)
<> (reverse (?*)) (reverse List (?*) ())
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
reverse (modal) = ladom test