Browse Source

update for new function stuff

Getty Ritter 1 year ago
parent
commit
204006d951
5 changed files with 30 additions and 22 deletions
  1. 2 2
      Makefile
  2. 4 4
      examples/halfling_ipa.matzo
  3. 10 7
      examples/peano.matzo
  4. 13 8
      examples/person.matzo
  5. 1 1
      examples/simple_ipa.matzo

+ 2 - 2
Makefile

@@ -1,9 +1,9 @@
 all: out/index.html out/dist/main.js
 
-matzo_web_bg.wasm: src/lib.rs Cargo.toml Cargo.lock
+pkg/matzo_web_bg.wasm: src/lib.rs Cargo.toml Cargo.lock
 	wasm-pack build --target web
 
-dist/main.js: js/*.js package.json
+dist/main.js: js/*.js package.json pkg/matzo_web_bg.wasm
 	yarn build
 
 out/index.html: index.html build.py

+ 4 - 4
examples/halfling_ipa.matzo

@@ -1,7 +1,7 @@
 (* these should probably be part of the stdlib eventually *)
-flatten := {[t] => tuple/fold[{ [x, xs] => x xs }, "", t]};
+fn flatten[t] => tuple/fold[fn {[x, xs] => x xs }, "", t];
 
-word := {[w] => flatten[tuple/map[orthography, w]]};
+fn word[w] => flatten[tuple/map[orthography, w]];
 wd := tuple/concat[<begin, middle, end>];
 middle := syll | tuple/concat[<syll, syll>] | tuple/concat[<syll, syll, syll>] | tuple/concat[<syll, syll, syll, syll>];
 syll := <cons, vowel>;
@@ -9,7 +9,7 @@ end := <cons, vowel, final>
      | 2: <cons, ("eː" | "a"), final>
      | <"r"> | <"n"> ;
 
-orthography := { [x] => case x in
+fn orthography[x] => case x in
   { "z"  => "s"
   ; "s"  => "ss"
   ; "dz" => "z"
@@ -31,7 +31,7 @@ orthography := { [x] => case x in
   ; "tɾ" => "tr"
   ; "ɾt" => "rt"
   ; _    => x
-  } };
+  };
 
 begin := <vowel> | <initcons, vowel>;
 

+ 10 - 7
examples/peano.matzo

@@ -1,15 +1,18 @@
-isZero := { [Z] => True; [<S,_>] => False };
-add := { [Z]     => { [y] => y }
-       ; [<S,x>] => { [y] => add[x][<S,y>] } };
+fn isZero { [Z] => True; [<S,_>] => False };
+fn add {
+  [Z]     => fn { [y] => y };
+  [<S,x>] => fn { [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 };
+fn if {
+  [True]  => fn { [x] => fn { [_] => x } };
+  [False] => fn { [_] => fn { [y] => y } };
+};
+fn minusOne { [Z] => Z; [<S,x>] => x };
 
 puts "S is " S;
 puts "Z is " Z;

+ 13 - 8
examples/person.matzo

@@ -1,5 +1,9 @@
 gender:= Male | Female | Unspec;
-byGender := { [m,f,n] => { [Male] => m; [Female] => f; [_] => n }};
+fn byGender[m,f,n] => fn {
+  [Male]   => m;
+  [Female] => f;
+  [_]      => n;
+};
 
 ending  := byGender["o","a","e"];
 pronoun := byGender["he","she","they"];
@@ -10,12 +14,12 @@ have    := byGender["has", "has", "have"];
 cons  ::= p t c d g r l m n x;
 vowel ::= a e i o u;
 
-name := { [g] => (vowel | "") rep[1..3, cons vowel] cons ending[g] };
+fn name[g] => (vowel | "") rep[1..3, cons vowel] cons ending[g];
 
 hairColor ::= black brown blonde;
 eyeColor  ::= brown green blue;
 
-job := { [g] =>
+fn job[g] =>
     "stonemason"
   | "baker"
   | "accountant"
@@ -23,8 +27,9 @@ job := { [g] =>
       { Male   => "fisherman"
       ; Female => "fisherwoman"
       ; _      => "fisher"
-      } };
-tool := { ["stonemason"] => "chisel"
+      };
+
+fn tool { ["stonemason"] => "chisel"
         ; ["baker"]      => "bowl"
         ; ["accountant"] => "tablet"
         ; [_]            => "fishing pole"
@@ -33,8 +38,8 @@ tool := { ["stonemason"] => "chisel"
 adjective ::= happy cheerful focused quiet meek rash;
 
 person :=
-  let fix my-gender := gender in {
-  let fix my-job := job[my-gender] in {
+  let fix my-gender := gender;
+      fix my-job := job[my-gender] in {
     se[
       "You come across",
       str/capitalize[name[my-gender]],
@@ -68,5 +73,5 @@ person :=
       adjective,
       "."
     ]
-  } };
+  };
 puts person;

+ 1 - 1
examples/simple_ipa.matzo

@@ -7,7 +7,7 @@ syll := tuple/flatten[cons, rime];
 
 word := tuple/flatten[tuple/rep[2..4, syll]];
 
-orthography := {
+fn orthography {
   ["ʃ"] => "sh";
   ["ŋ"] => "ng";
   ["ɾ"] => "r";