浏览代码

add some computation-heavy examples

Getty Ritter 3 年之前
父节点
当前提交
2dc701b1c2
共有 2 个文件被更改,包括 81 次插入0 次删除
  1. 48 0
      examples/halfling_ipa.matzo
  2. 33 0
      examples/peano.matzo

+ 48 - 0
examples/halfling_ipa.matzo

@@ -0,0 +1,48 @@
+tuple-map := { func => {tup => tuple-fold.<{xs => {x => concat.<xs, <func.x>>}}, <>, tup>}};
+
+flatten := { t => tuple-fold.<{ x => { xs => x xs } }, "", t> };
+word := { w => flatten.(tuple-map.orthography.w) };
+wd := concat.<begin, middle, end>;
+middle := syll | concat.<syll, syll> | concat.<syll, syll, syll> | concat.<syll, syll, syll, syll>;
+syll := <cons, vowel>;
+end := <cons, vowel, final>
+     | 2: <cons, ("eː" | "a"), final>
+     | <"r"> | <"n"> ;
+
+orthography :=
+  { "z"  => "s"
+  ; "s"  => "ss"
+  ; "dz" => "z"
+  ; "kʷ" => "qu"
+  ; "k"  => "c"
+  ; "x"  => "ch"
+  ; "ʎ"  => "lh"
+  ; "ɲ"  => "nh"
+  ; "ʃ"  => "sc"
+  ; "ts" => "tz"
+  ; "aː" => "á"
+  ; "eː" => "é"
+  ; "iː" => "í"
+  ; "oː" => "ó"
+  ; "uː" => "ú"
+  ; "ɛ"  => "è"
+  ; "ɔ"  => "o"
+  ; "ɾ"  => "r"
+  ; "tɾ" => "tr"
+  ; "ɾt" => "rt"
+  ; x    => x
+  };
+
+begin := <vowel> | <initcons, vowel>;
+
+cons ::= b k d d x d f g g ɲ h j l l l ʎ m m m n n n
+         p kʷ ɾ z z z s s s ʃ ʃ t t t tg tj ts ts tɾ ɾt v dz;
+initcons ::= b k d x d f g ɲ h j l m n p kʷ ɾ s ʃ t v;
+vowel := 4: commonvowel | uncommonvowel;
+commonvowel ::= a i u e eː o;
+uncommonvowel ::= aː ɛ oː ɔ iː uː;
+final := "s" | 6: "";
+
+
+fix wd;
+puts (word.wd) " (pronounced /" (flatten.wd) "/)";

+ 33 - 0
examples/peano.matzo

@@ -0,0 +1,33 @@
+isZero := { Z => True; <S,_> => False };
+add := { Z     => { y => y }
+       ; <S,x> => { y => add.x.<S,y> } };
+incr := add.<S,Z>;
+
+two  := <S,<S,Z>>;
+four := <S,<S,<S,<S,Z>>>>;
+
+if := { True  => { x => { _ => x } }
+      ; False => { _ => { y => y } }
+      };
+minusOne := { Z => Z; <S,x> => x };
+
+puts "S is " S;
+puts "Z is " Z;
+
+puts "True is " True;
+puts "False is " False;
+
+puts "Is 0 zero?";
+puts isZero.Z;
+
+puts "Is 4 zero?";
+puts isZero.four;
+
+puts "2 + 4 = ";
+puts add.four.two;
+
+puts "Is zero zero?";
+puts if.(isZero.Z)."yes"."no";
+
+puts "Is 0+1 zero?";
+puts if.(isZero.(incr.Z))."yes"."no";