From 4690ce81e079fc58cae8d6d583e5e3eb3ed81a83 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 9 Mar 2016 02:56:27 -0800 Subject: 2743 Looks like "TOhtml | " doesn't work on Mac OS X for some reason.. --- html/025compare.cc.html | 234 +++++++++++++++++++++++++++--------------------- 1 file changed, 133 insertions(+), 101 deletions(-) (limited to 'html/025compare.cc.html') diff --git a/html/025compare.cc.html b/html/025compare.cc.html index 19eee8a5..060286ea 100644 --- a/html/025compare.cc.html +++ b/html/025compare.cc.html @@ -3,34 +3,27 @@ Mu - 025compare.cc - - + + - - + - - -
+
 //: Comparison primitives
 
 :(before "End Primitive Recipe Declarations")
@@ -38,19 +31,27 @@ EQUAL,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "equal", EQUAL);
 :(before "End Primitive Recipe Checks")
-case EQUAL: {
-  if (SIZE(inst.ingredients) <= 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+case EQUAL: {
+  if (SIZE(inst.ingredients) <= 1) {
+    raise << maybe(get(Recipe, r).name) << "'equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (SIZE(inst.products) > 1) {
+    raise << maybe(get(Recipe, r).name) << "'equal' yields exactly one product in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "'equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end();
     break;
   }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case EQUAL: {
-  vector<double>& exemplar = ingredients.at(0);
-  bool result = true;
-  for (long long int i = 1; i < SIZE(ingredients); ++i) {
-    if (!equal(ingredients.at(i).begin(), ingredients.at(i).end(), exemplar.begin())) {
+case EQUAL: {
+  vector<double>& exemplar = ingredients.at(0);
+  bool result = true;
+  for (long long int i = 1; i < SIZE(ingredients); ++i) {
+    if (!equal(ingredients.at(i).begin(), ingredients.at(i).end(), exemplar.begin())) {
       result = false;
       break;
     }
@@ -61,34 +62,34 @@ case EQUAL: {
 }
 
 :(scenario equal)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 33
-  3:number <- equal 1:number, 2:number
+  3:boolean <- equal 1:number, 2:number
 ]
 +mem: location 1 is 34
 +mem: location 2 is 33
 +mem: storing 0 in location 3
 
 :(scenario equal_2)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 34
-  3:number <- equal 1:number, 2:number
+  3:boolean <- equal 1:number, 2:number
 ]
 +mem: location 1 is 34
 +mem: location 2 is 34
 +mem: storing 1 in location 3
 
 :(scenario equal_multiple)
-recipe main [
-  1:number <- equal 34, 34, 34
+def main [
+  1:boolean <- equal 34, 34, 34
 ]
 +mem: storing 1 in location 1
 
 :(scenario equal_multiple_2)
-recipe main [
-  1:number <- equal 34, 34, 35
+def main [
+  1:boolean <- equal 34, 34, 35
 ]
 +mem: storing 0 in location 1
 
@@ -97,24 +98,32 @@ GREATER_THAN,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "greater-than", GREATER_THAN);
 :(before "End Primitive Recipe Checks")
-case GREATER_THAN: {
-  if (SIZE(inst.ingredients) <= 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'greater-than' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+case GREATER_THAN: {
+  if (SIZE(inst.ingredients) <= 1) {
+    raise << maybe(get(Recipe, r).name) << "'greater-than' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
     break;
   }
-  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
-    if (!is_mu_number(inst.ingredients.at(i))) {
-      raise_error << maybe(get(Recipe, r).name) << "'greater-than' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
+  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
+    if (!is_mu_number(inst.ingredients.at(i))) {
+      raise << maybe(get(Recipe, r).name) << "'greater-than' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
       goto finish_checking_instruction;
     }
   }
+  if (SIZE(inst.products) > 1) {
+    raise << maybe(get(Recipe, r).name) << "'greater-than' yields exactly one product in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "'greater-than' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case GREATER_THAN: {
-  bool result = true;
-  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
-    if (ingredients.at(i-1).at(0) <= ingredients.at(i).at(0)) {
+case GREATER_THAN: {
+  bool result = true;
+  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
+    if (ingredients.at(i-1).at(0) <= ingredients.at(i).at(0)) {
       result = false;
     }
   }
@@ -124,7 +133,7 @@ case GREATER_THAN: {
 }
 
 :(scenario greater_than)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 33
   3:boolean <- greater-than 1:number, 2:number
@@ -132,7 +141,7 @@ recipe main [
 +mem: storing 1 in location 3
 
 :(scenario greater_than_2)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 34
   3:boolean <- greater-than 1:number, 2:number
@@ -140,13 +149,13 @@ recipe main [
 +mem: storing 0 in location 3
 
 :(scenario greater_than_multiple)
-recipe main [
+def main [
   1:boolean <- greater-than 36, 35, 34
 ]
 +mem: storing 1 in location 1
 
 :(scenario greater_than_multiple_2)
-recipe main [
+def main [
   1:boolean <- greater-than 36, 35, 35
 ]
 +mem: storing 0 in location 1
@@ -156,24 +165,32 @@ LESSER_THAN,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "lesser-than", LESSER_THAN);
 :(before "End Primitive Recipe Checks")
-case LESSER_THAN: {
-  if (SIZE(inst.ingredients) <= 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'lesser-than' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+case LESSER_THAN: {
+  if (SIZE(inst.ingredients) <= 1) {
+    raise << maybe(get(Recipe, r).name) << "'lesser-than' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
     break;
   }
-  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
-    if (!is_mu_number(inst.ingredients.at(i))) {
-      raise_error << maybe(get(Recipe, r).name) << "'lesser-than' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
+  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
+    if (!is_mu_number(inst.ingredients.at(i))) {
+      raise << maybe(get(Recipe, r).name) << "'lesser-than' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
       goto finish_checking_instruction;
     }
   }
+  if (SIZE(inst.products) > 1) {
+    raise << maybe(get(Recipe, r).name) << "'lesser-than' yields exactly one product in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "'lesser-than' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case LESSER_THAN: {
-  bool result = true;
-  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
-    if (ingredients.at(i-1).at(0) >= ingredients.at(i).at(0)) {
+case LESSER_THAN: {
+  bool result = true;
+  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
+    if (ingredients.at(i-1).at(0) >= ingredients.at(i).at(0)) {
       result = false;
     }
   }
@@ -183,7 +200,7 @@ case LESSER_THAN: {
 }
 
 :(scenario lesser_than)
-recipe main [
+def main [
   1:number <- copy 32
   2:number <- copy 33
   3:boolean <- lesser-than 1:number, 2:number
@@ -191,7 +208,7 @@ recipe main [
 +mem: storing 1 in location 3
 
 :(scenario lesser_than_2)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 33
   3:boolean <- lesser-than 1:number, 2:number
@@ -199,13 +216,13 @@ recipe main [
 +mem: storing 0 in location 3
 
 :(scenario lesser_than_multiple)
-recipe main [
+def main [
   1:boolean <- lesser-than 34, 35, 36
 ]
 +mem: storing 1 in location 1
 
 :(scenario lesser_than_multiple_2)
-recipe main [
+def main [
   1:boolean <- lesser-than 34, 35, 35
 ]
 +mem: storing 0 in location 1
@@ -215,24 +232,32 @@ GREATER_OR_EQUAL,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "greater-or-equal", GREATER_OR_EQUAL);
 :(before "End Primitive Recipe Checks")
-case GREATER_OR_EQUAL: {
-  if (SIZE(inst.ingredients) <= 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'greater-or-equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+case GREATER_OR_EQUAL: {
+  if (SIZE(inst.ingredients) <= 1) {
+    raise << maybe(get(Recipe, r).name) << "'greater-or-equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
     break;
   }
-  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
-    if (!is_mu_number(inst.ingredients.at(i))) {
-      raise_error << maybe(get(Recipe, r).name) << "'greater-or-equal' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
+  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
+    if (!is_mu_number(inst.ingredients.at(i))) {
+      raise << maybe(get(Recipe, r).name) << "'greater-or-equal' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
       goto finish_checking_instruction;
     }
   }
+  if (SIZE(inst.products) > 1) {
+    raise << maybe(get(Recipe, r).name) << "'greater-or-equal' yields exactly one product in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "'greater-or-equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case GREATER_OR_EQUAL: {
-  bool result = true;
-  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
-    if (ingredients.at(i-1).at(0) < ingredients.at(i).at(0)) {
+case GREATER_OR_EQUAL: {
+  bool result = true;
+  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
+    if (ingredients.at(i-1).at(0) < ingredients.at(i).at(0)) {
       result = false;
     }
   }
@@ -242,38 +267,38 @@ case GREATER_OR_EQUAL: {
 }
 
 :(scenario greater_or_equal)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 33
-  3:boolean <- greater-or-equal 1:number, 2:number
+  3:boolean <- greater-or-equal 1:number, 2:number
 ]
 +mem: storing 1 in location 3
 
 :(scenario greater_or_equal_2)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 34
-  3:boolean <- greater-or-equal 1:number, 2:number
+  3:boolean <- greater-or-equal 1:number, 2:number
 ]
 +mem: storing 1 in location 3
 
 :(scenario greater_or_equal_3)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 35
-  3:boolean <- greater-or-equal 1:number, 2:number
+  3:boolean <- greater-or-equal 1:number, 2:number
 ]
 +mem: storing 0 in location 3
 
 :(scenario greater_or_equal_multiple)
-recipe main [
-  1:boolean <- greater-or-equal 36, 35, 35
+def main [
+  1:boolean <- greater-or-equal 36, 35, 35
 ]
 +mem: storing 1 in location 1
 
 :(scenario greater_or_equal_multiple_2)
-recipe main [
-  1:boolean <- greater-or-equal 36, 35, 36
+def main [
+  1:boolean <- greater-or-equal 36, 35, 36
 ]
 +mem: storing 0 in location 1
 
@@ -282,24 +307,32 @@ LESSER_OR_EQUAL,
 :(before "End Primitive Recipe Numbers")
 put(Recipe_ordinal, "lesser-or-equal", LESSER_OR_EQUAL);
 :(before "End Primitive Recipe Checks")
-case LESSER_OR_EQUAL: {
-  if (SIZE(inst.ingredients) <= 1) {
-    raise_error << maybe(get(Recipe, r).name) << "'lesser-or-equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
+case LESSER_OR_EQUAL: {
+  if (SIZE(inst.ingredients) <= 1) {
+    raise << maybe(get(Recipe, r).name) << "'lesser-or-equal' needs at least two ingredients to compare in '" << to_string(inst) << "'\n" << end();
     break;
   }
-  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
-    if (!is_mu_number(inst.ingredients.at(i))) {
-      raise_error << maybe(get(Recipe, r).name) << "'lesser-or-equal' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
+  for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
+    if (!is_mu_number(inst.ingredients.at(i))) {
+      raise << maybe(get(Recipe, r).name) << "'lesser-or-equal' can only compare numbers; got " << inst.ingredients.at(i).original_string << '\n' << end();
       goto finish_checking_instruction;
     }
   }
+  if (SIZE(inst.products) > 1) {
+    raise << maybe(get(Recipe, r).name) << "'greater-or-equal' yields exactly one product in '" << to_string(inst) << "'\n" << end();
+    break;
+  }
+  if (!inst.products.empty() && !is_dummy(inst.products.at(0)) && !is_mu_boolean(inst.products.at(0))) {
+    raise << maybe(get(Recipe, r).name) << "'greater-or-equal' should yield a boolean, but got " << inst.products.at(0).original_string << '\n' << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case LESSER_OR_EQUAL: {
-  bool result = true;
-  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
-    if (ingredients.at(i-1).at(0) > ingredients.at(i).at(0)) {
+case LESSER_OR_EQUAL: {
+  bool result = true;
+  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
+    if (ingredients.at(i-1).at(0) > ingredients.at(i).at(0)) {
       result = false;
     }
   }
@@ -309,41 +342,40 @@ case LESSER_OR_EQUAL: {
 }
 
 :(scenario lesser_or_equal)
-recipe main [
+def main [
   1:number <- copy 32
   2:number <- copy 33
-  3:boolean <- lesser-or-equal 1:number, 2:number
+  3:boolean <- lesser-or-equal 1:number, 2:number
 ]
 +mem: storing 1 in location 3
 
 :(scenario lesser_or_equal_2)
-recipe main [
+def main [
   1:number <- copy 33
   2:number <- copy 33
-  3:boolean <- lesser-or-equal 1:number, 2:number
+  3:boolean <- lesser-or-equal 1:number, 2:number
 ]
 +mem: storing 1 in location 3
 
 :(scenario lesser_or_equal_3)
-recipe main [
+def main [
   1:number <- copy 34
   2:number <- copy 33
-  3:boolean <- lesser-or-equal 1:number, 2:number
+  3:boolean <- lesser-or-equal 1:number, 2:number
 ]
 +mem: storing 0 in location 3
 
 :(scenario lesser_or_equal_multiple)
-recipe main [
-  1:boolean <- lesser-or-equal 34, 35, 35
+def main [
+  1:boolean <- lesser-or-equal 34, 35, 35
 ]
 +mem: storing 1 in location 1
 
 :(scenario lesser_or_equal_multiple_2)
-recipe main [
-  1:boolean <- lesser-or-equal 34, 35, 34
+def main [
+  1:boolean <- lesser-or-equal 34, 35, 34
 ]
 +mem: storing 0 in location 1
 
- -- cgit 1.4.1-2-gfad0