about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nix-repl.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/nix-repl.cc b/nix-repl.cc
index 10e91ec5328e..9858a034d728 100644
--- a/nix-repl.cc
+++ b/nix-repl.cc
@@ -30,6 +30,7 @@ struct NixRepl
     void processLine(string line);
     void addVar(const Symbol & name, Value * v);
     Expr * parseString(string s);
+    void evalString(string s, Value & v);
 };
 
 
@@ -91,22 +92,26 @@ void NixRepl::mainLoop()
 void NixRepl::processLine(string line)
 {
     if (string(line, 0, 2) == ":a") {
-        Expr * e = parseString(string(line, 2));
         Value v;
-        e->eval(state, *env, v);
+        evalString(string(line, 2), v);
         state.forceAttrs(v);
         foreach (Bindings::iterator, i, *v.attrs)
             addVar(i->name, i->value);
     }
 
+    else if (string(line, 0, 2) == ":t") {
+        Value v;
+        evalString(string(line, 2), v);
+        std::cout << showType(v) << std::endl;
+    }
+
     else if (string(line, 0, 1) == ":") {
         throw Error(format("unknown command ‘%1%’") % string(line, 0, 2));
     }
 
     else {
-        Expr * e = parseString(line);
         Value v;
-        e->eval(state, *env, v);
+        evalString(line, v);
         state.strictForceValue(v);
         std::cout << v << std::endl;
     }
@@ -127,6 +132,14 @@ Expr * NixRepl::parseString(string s)
 }
 
 
+void NixRepl::evalString(string s, Value & v)
+{
+    Expr * e = parseString(s);
+    e->eval(state, *env, v);
+    state.forceValue(v);
+}
+
+
 void run(nix::Strings args)
 {
     NixRepl repl;