mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 15:26:17 +02:00
* lessThan primitive for integer comparison.
This commit is contained in:
parent
2ab4bc44c7
commit
df8873e14a
2 changed files with 13 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue