From df8873e14ad071812e27f38b69783f04dbae5f44 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Sun, 24 Sep 2006 15:21:48 +0000
Subject: [PATCH] * lessThan primitive for integer comparison.

---
 src/libexpr/primops.cc              | 9 +++++++++
 tests/lang/eval-okay-arithmetic.nix | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 1739b6656..16d165634 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -779,6 +779,14 @@ static Expr primAdd(EvalState & state, const ATermVector & args)
 }
 
 
+static Expr primLessThan(EvalState & state, const ATermVector & args)
+{
+    int i1 = evalInt(state, args[0]);
+    int i2 = evalInt(state, args[1]);
+    return makeBool(i1 < i2);
+}
+
+
 void EvalState::addPrimOps()
 {
     addPrimOp("builtins", 0, primBuiltins);
@@ -810,6 +818,7 @@ void EvalState::addPrimOps()
     addPrimOp("removeAttrs", 2, primRemoveAttrs);
     addPrimOp("relativise", 2, primRelativise);
     addPrimOp("__add", 2, primAdd);
+    addPrimOp("__lessThan", 2, primLessThan);
 }
 
  
diff --git a/tests/lang/eval-okay-arithmetic.nix b/tests/lang/eval-okay-arithmetic.nix
index 735f01cf4..ac1fcb73c 100644
--- a/tests/lang/eval-okay-arithmetic.nix
+++ b/tests/lang/eval-okay-arithmetic.nix
@@ -2,7 +2,10 @@ with import ./lib.nix;
 
 let {
 
-  range = first: last: [first] ++ (if first == last then [] else range (builtins.add first 1) last);
+  range = first: last:
+    if builtins.lessThan last first
+    then []
+    else [first] ++ range (builtins.add first 1) last;
 
   /* Supposedly tail recursive version:
   
-- 
GitLab