about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-05-18T17·19+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-05-18T17·19+0000
commit040140dd1c3c11e3aa1ca486c3f3596cbe99c008 (patch)
tree226df5b0dfc792d6409fede65b65ac2170821138 /src/libexpr/primops.cc
parent109cde670629a0f022de1d875b55bb2f5243b271 (diff)
* Added a primop `removeAttrs' to remove attributes from a set, e.g.,
  `removeAttrs attrs ["x", "y"]' returns the set `attrs' with the
  attributes named `x' and `y' removed.  It is not an error for the
  named attributes to be missing from the input set.

Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index e3dd2db18d..b0986028ee 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -444,6 +444,23 @@ static Expr primCurrentTime(EvalState & state, const ATermVector & args)
 }
 
 
+static Expr primRemoveAttrs(EvalState & state, const ATermVector & args)
+{
+    ATermMap attrs;
+    queryAllAttrs(evalExpr(state, args[0]), attrs, true);
+    
+    ATermList list;
+    if (!matchList(evalExpr(state, args[1]), list))
+        throw Error("`removeAttrs' expects a list as its second argument");
+
+    for (ATermIterator i(list); i; ++i)
+        /* It's not an error for *i not to exist. */
+        attrs.remove(evalString(state, *i));
+
+    return makeAttrs(attrs);
+}
+
+
 void EvalState::addPrimOps()
 {
     addPrimOp("true", 0, primTrue);
@@ -460,6 +477,7 @@ void EvalState::addPrimOps()
     addPrimOp("isNull", 1, primIsNull);
 
     addPrimOp("map", 2, primMap);
+    addPrimOp("removeAttrs", 2, primRemoveAttrs);
 }