about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-18 08:33:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-18 08:33:20 -0700
commit8e64ab8b177a315c6c6c859dc61133e8a2331bd7 (patch)
treecd77162570870f7c04269a29bc9469111afbba5d
parent09db6ed0371720683debe1fecbe3be77e9555c9d (diff)
downloadmu-8e64ab8b177a315c6c6c859dc61133e8a2331bd7.tar.gz
3514
Let's constrain 'push' on lists to always modify its ingredient.

That makes some possibilities more verbose, such as lists that share a
common tail. But may be worthwhile to get better errors in the common
use-case.
-rw-r--r--057immutable.cc17
-rw-r--r--064list.mu9
2 files changed, 20 insertions, 6 deletions
diff --git a/057immutable.cc b/057immutable.cc
index 4dc7a2aa..6a5d97d6 100644
--- a/057immutable.cc
+++ b/057immutable.cc
@@ -563,8 +563,21 @@ $error: 0
 if (has_property(current_ingredient, "contained-in")) {
   const string_tree* tmp = property(current_ingredient, "contained-in");
   if (!tmp->atom
-      || !is_present_in_ingredients(caller, tmp->value)
-      || !is_present_in_products(caller, tmp->value))
+      || (!is_present_in_ingredients(caller, tmp->value)
+          && !is_present_in_products(caller, tmp->value))) {
     raise << maybe(caller.name) << "/contained-in can only point to another ingredient or product, but got '" << to_string(property(current_ingredient, "contained-in")) << "'\n" << end();
+  }
   continue;
 }
+
+:(scenario contained_in_check)
+container test-list [
+  value:num
+  next:&:test-list
+]
+def test-remove x:&:test-list/contained-in:result, from:&:test-list -> result:&:test-list [
+  local-scope
+  load-ingredients
+  result <- copy 0
+]
+$error: 0
diff --git a/064list.mu b/064list.mu
index cf7be09c..baf3d7bf 100644
--- a/064list.mu
+++ b/064list.mu
@@ -8,11 +8,12 @@ container list:_elem [
   next:&:list:_elem
 ]
 
-def push x:_elem, in:&:list:_elem -> result:&:list:_elem [
+def push x:_elem, l:&:list:_elem -> l:&:list:_elem [
   local-scope
   load-ingredients
-  result <- new {(list _elem): type}
-  *result <- merge x, in
+  result:&:list:_elem <- new {(list _elem): type}
+  *result <- merge x, l
+  reply result
 ]
 
 def first in:&:list:_elem -> result:_elem [
@@ -260,7 +261,7 @@ scenario removing-from-singleton-list [
 
 # reverse the elements of a list
 # (contributed by Caleb Couch)
-def reverse list:&:list:_elem temp:&:list:_elem -> result:&:list:_elem [
+def reverse list:&:list:_elem temp:&:list:_elem/contained-in:result -> result:&:list:_elem [
   local-scope
   load-ingredients
   reply-unless list, temp