about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-05-16T16·17+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-05-16T16·17+0000
commitbddc83a1487e9f3c1bb3ac2279c0238e8e6c3ff3 (patch)
tree1466672b9f0eb9096cc33af950e964bfdf044f4d /src/libexpr/primops.cc
parentca00aa11714921804afb490d0613086f549fb894 (diff)
* New builtin function "isFunction". You're not supposed to use it
  ;-)
* Channels: fix channels that are plain lists of derivations (like
  strategoxt-unstable) instead  of functions (like nixpkgs-unstable).
  This fixes the error message "error: the left-hand side of the
  function call is neither a function nor a primop (built-in
  operation) but a list".

Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index c7fbca0bb5..95440c9bf6 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -114,6 +114,18 @@ static Expr prim_isNull(EvalState & state, const ATermVector & args)
 }
 
 
+/* Determine whether the argument is a function. */
+static Expr prim_isFunction(EvalState & state, const ATermVector & args)
+{
+    Expr e = evalExpr(state, args[0]);
+    ATermList formals;
+    ATerm name, body, pos;
+    return makeBool(
+        matchFunction(e, formals, body, pos) ||
+        matchFunction1(e, name, body, pos));
+}
+
+
 static Path findDependency(Path dir, string dep)
 {
     if (dep[0] == '/') throw EvalError(
@@ -884,6 +896,7 @@ void EvalState::addPrimOps()
     // Miscellaneous
     addPrimOp("import", 1, prim_import);
     addPrimOp("isNull", 1, prim_isNull);
+    addPrimOp("__isFunction", 1, prim_isFunction);
     addPrimOp("dependencyClosure", 1, prim_dependencyClosure);
     addPrimOp("abort", 1, prim_abort);
     addPrimOp("throw", 1, prim_throw);