fix(depotfmt): only exclude *imported* tvix tests
When we added the Nix language test suite in cl/6126, we excluded the whole tvix tests folder from Nix formatting. This is unintentional, as we probably want *our* tests to be formatted correctly. Change-Id: I2b66d79e30fae17e75d5a1f8c44e279886091c5f Reviewed-on: https://cl.tvl.fyi/c/depot/+/11154 Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
d5b6704d3d
commit
d3534ee051
91 changed files with 412 additions and 272 deletions
|
@ -23,7 +23,7 @@ let
|
||||||
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
||||||
includes = [ "*.nix" ]
|
includes = [ "*.nix" ]
|
||||||
excludes = [
|
excludes = [
|
||||||
"tvix/eval/src/tests/*",
|
"tvix/eval/src/tests/nix_tests/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
[formatter.rust]
|
[formatter.rust]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
builtins.genList (_: {}.foo) 1
|
builtins.genList (_: { }.foo) 1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
({x}: x) {x = 1; y = 2;}
|
({ x }: x) { x = 1; y = 2; }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
let {
|
let {
|
||||||
attrs = {x = 123; y = 456;};
|
attrs = { x = 123; y = 456; };
|
||||||
|
|
||||||
body = (removeAttrs attrs ["x"]).x;
|
body = (removeAttrs attrs [ "x" ]).x;
|
||||||
}
|
}
|
|
@ -2,7 +2,8 @@ let
|
||||||
# There is no syntax for accessing this identifier in an ordinary
|
# There is no syntax for accessing this identifier in an ordinary
|
||||||
# way.
|
# way.
|
||||||
"foo bar" = 42;
|
"foo bar" = 42;
|
||||||
in ({
|
in
|
||||||
|
({
|
||||||
# but we *can* inherit it back out
|
# but we *can* inherit it back out
|
||||||
inherit "foo bar";
|
inherit "foo bar";
|
||||||
})."foo bar"
|
})."foo bar"
|
||||||
|
|
|
@ -3,5 +3,5 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
# The function application here will become a thunk which verifies that
|
# The function application here will become a thunk which verifies that
|
||||||
# assert forces the condition expression correctly.
|
# assert forces the condition expression correctly.
|
||||||
assert condition 21 42; 21
|
assert condition 21 42; 21
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
# the 'from' part of an `inherit` can be any expression.
|
# the 'from' part of an `inherit` can be any expression.
|
||||||
{ inherit ({a = 15;}) a; }.a
|
{ inherit ({ a = 15; }) a; }.a
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{} // { a = "ok"; }
|
{ } // { a = "ok"; }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{ a = "ok"; } // {}
|
{ a = "ok"; } // { }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval ( builtins.baseNameOf (throw "jill") )).success
|
(builtins.tryEval (builtins.baseNameOf (throw "jill"))).success
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[
|
[
|
||||||
(builtins.attrNames {})
|
(builtins.attrNames { })
|
||||||
(builtins.attrNames { foo = 1; bar = 2; baz = 3; })
|
(builtins.attrNames { foo = 1; bar = 2; baz = 3; })
|
||||||
(builtins.attrNames { Foo = 1; bar = 2; Baz = 3; })
|
(builtins.attrNames { Foo = 1; bar = 2; Baz = 3; })
|
||||||
(builtins.attrNames {
|
(builtins.attrNames {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[
|
[
|
||||||
(builtins.attrValues {})
|
(builtins.attrValues { })
|
||||||
(builtins.attrValues { foo = 1; bar = 2; baz = 3; })
|
(builtins.attrValues { foo = 1; bar = 2; baz = 3; })
|
||||||
]
|
]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[ builtins ] == [ builtins.builtins ]
|
[ builtins ] == [ builtins.builtins ]
|
||||||
|
|
|
@ -4,7 +4,7 @@ let
|
||||||
ord1 = builtins.compareVersions a b;
|
ord1 = builtins.compareVersions a b;
|
||||||
ord2 = builtins.compareVersions b a;
|
ord2 = builtins.compareVersions b a;
|
||||||
in
|
in
|
||||||
assert ord1 == -ord2; ord1;
|
assert ord1 == -ord2; ord1;
|
||||||
in
|
in
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [] (builtins.throw "a") ]) (builtins.concatLists [ [] [] [ builtins.throw "a" ] ]) ]
|
map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [ ] (builtins.throw "a") ]) (builtins.concatLists [ [ ] [ ] [ builtins.throw "a" ] ]) ]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: []) (builtins.throw "a")) ]
|
map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: [ ]) (builtins.throw "a")) ]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
map (e: (builtins.tryEval e).success) [
|
map (e: (builtins.tryEval e).success) [
|
||||||
(builtins.foldl' (builtins.throw "a") {} [ {} {} {} ])
|
(builtins.foldl' (builtins.throw "a") { } [{ } { } { }])
|
||||||
(builtins.foldl' (x: y: x // y) {} (builtins.throw "b"))
|
(builtins.foldl' (x: y: x // y) { } (builtins.throw "b"))
|
||||||
(builtins.foldl' (_: _: builtins.throw "x") {} [ {} ])
|
(builtins.foldl' (_: _: builtins.throw "x") { } [{ }])
|
||||||
(builtins.foldl' (x: y: x // y) (builtins.throw "x") [ {} ])
|
(builtins.foldl' (x: y: x // y) (builtins.throw "x") [{ }])
|
||||||
(builtins.foldl' (x: y: x // y) {} [ {} { a = builtins.throw "z"; } {} ])
|
(builtins.foldl' (x: y: x // y) { } [{ } { a = builtins.throw "z"; } { }])
|
||||||
(builtins.foldl' (x: y: x // y) {} [ {} { b = 3; a = builtins.throw "u"; } {} ])
|
(builtins.foldl' (x: y: x // y) { } [{ } { b = 3; a = builtins.throw "u"; } { }])
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,13 +3,13 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
# key needs to be a list since it uses comparison, not equality checks:
|
# key needs to be a list since it uses comparison, not equality checks:
|
||||||
# lists are comparable in Nix if all non-comparable items in them are equal (e.g.
|
# lists are comparable in Nix if all non-comparable items in them are equal (e.g.
|
||||||
# functions, attribute sets).
|
# functions, attribute sets).
|
||||||
builtins.genericClosure {
|
builtins.genericClosure {
|
||||||
startSet = [
|
startSet = [
|
||||||
{ key = [ { inherit foo; } ]; val = null; }
|
{ key = [{ inherit foo; }]; val = null; }
|
||||||
];
|
];
|
||||||
operator = { val, ... }: if val != null then [] else [
|
operator = { val, ... }: if val != null then [ ] else [
|
||||||
{ key = [ { inherit foo; } ]; val = throw "no pointer equality? 🥺👉👈"; }
|
{ key = [{ inherit foo; }]; val = throw "no pointer equality? 🥺👉👈"; }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
builtins.groupBy
|
builtins.groupBy
|
||||||
(v: v.x)
|
(v: v.x)
|
||||||
[ (rec { y = x; x = "fred"; }) ]
|
[ (rec { y = x; x = "fred"; }) ]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
(builtins.hasAttr "bar" { foo = 1; bar = 2; baz = 3; })
|
(builtins.hasAttr "bar" { foo = 1; bar = 2; baz = 3; })
|
||||||
(builtins.hasAttr "baz" { foo = 1; bar = 2; baz = 3; })
|
(builtins.hasAttr "baz" { foo = 1; bar = 2; baz = 3; })
|
||||||
(builtins.hasAttr "FOO" { foo = 1; bar = 2; baz = 3; })
|
(builtins.hasAttr "FOO" { foo = 1; bar = 2; baz = 3; })
|
||||||
(builtins.hasAttr "foo" {})
|
(builtins.hasAttr "foo" { })
|
||||||
(builtins.hasAttr ("f" + "o" + "o") { foo = 1; })
|
(builtins.hasAttr ("f" + "o" + "o") { foo = 1; })
|
||||||
(builtins.hasAttr ("b" + "a" + "r") { foo = 1; })
|
(builtins.hasAttr ("b" + "a" + "r") { foo = 1; })
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[
|
[
|
||||||
(builtins.length [])
|
(builtins.length [ ])
|
||||||
(builtins.length [ 1 ])
|
(builtins.length [ 1 ])
|
||||||
(builtins.length [ "one" "two" "three" ])
|
(builtins.length [ "one" "two" "three" ])
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
map (e: (builtins.tryEval e).success) [
|
map (e: (builtins.tryEval e).success) [
|
||||||
(builtins.listToAttrs [ { name = builtins.throw "a"; value = "b"; } ])
|
(builtins.listToAttrs [{ name = builtins.throw "a"; value = "b"; }])
|
||||||
(builtins.listToAttrs [ { name = "a"; value = builtins.throw "b"; } ])
|
(builtins.listToAttrs [{ name = "a"; value = builtins.throw "b"; }])
|
||||||
(builtins.listToAttrs [ { name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; } ])
|
(builtins.listToAttrs [{ name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; }])
|
||||||
(builtins.listToAttrs [ { name = "a"; value = "b"; } (builtins.throw "e") ])
|
(builtins.listToAttrs [{ name = "a"; value = "b"; } (builtins.throw "e")])
|
||||||
(builtins.listToAttrs (builtins.throw "f"))
|
(builtins.listToAttrs (builtins.throw "f"))
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[
|
[
|
||||||
(builtins.partition (_: true) [ 1 2 3 4 5])
|
(builtins.partition (_: true) [ 1 2 3 4 5 ])
|
||||||
(builtins.partition (_: false) [ 1 2 3 4 5])
|
(builtins.partition (_: false) [ 1 2 3 4 5 ])
|
||||||
(builtins.partition (x: x == 2) [ 1 2 3 4 5])
|
(builtins.partition (x: x == 2) [ 1 2 3 4 5 ])
|
||||||
|
|
||||||
(builtins.partition (x: (builtins.length x) > 1) [
|
(builtins.partition (x: (builtins.length x) > 1) [
|
||||||
[ 1 ]
|
[ 1 ]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
map (e: (builtins.tryEval e).success) [
|
map (e: (builtins.tryEval e).success) [
|
||||||
(builtins.removeAttrs (builtins.throw "a") [ "a" ])
|
(builtins.removeAttrs (builtins.throw "a") [ "a" ])
|
||||||
(builtins.removeAttrs { a = {}; } (builtins.throw "b"))
|
(builtins.removeAttrs { a = { }; } (builtins.throw "b"))
|
||||||
(builtins.removeAttrs { a = builtins.throw "b"; } [ "a" ])
|
(builtins.removeAttrs { a = builtins.throw "b"; } [ "a" ])
|
||||||
(builtins.removeAttrs { "${builtins.throw "c"}" = "b"; } [ "c" ])
|
(builtins.removeAttrs { "${builtins.throw "c"}" = "b"; } [ "c" ])
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[
|
[
|
||||||
(builtins.replaceStrings ["oo" "a"] ["a" "i"] "foobar")
|
(builtins.replaceStrings [ "oo" "a" ] [ "a" "i" ] "foobar")
|
||||||
(builtins.replaceStrings ["o"] ["a"] "a")
|
(builtins.replaceStrings [ "o" ] [ "a" ] "a")
|
||||||
(builtins.replaceStrings ["" ""] ["1" "2"] "a")
|
(builtins.replaceStrings [ "" "" ] [ "1" "2" ] "a")
|
||||||
(builtins.replaceStrings ["a" "b" "c"] ["A" "B" "C"] "abc")
|
(builtins.replaceStrings [ "a" "b" "c" ] [ "A" "B" "C" ] "abc")
|
||||||
]
|
]
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
];
|
];
|
||||||
operator = { key, initial, ... }:
|
operator = { key, initial, ... }:
|
||||||
if initial
|
if initial
|
||||||
then [ { key = key - 1; initial = false; value = throw "lol"; } ]
|
then [{ key = key - 1; initial = false; value = throw "lol"; }]
|
||||||
else [ ];
|
else [ ];
|
||||||
}))
|
}))
|
||||||
(builtins.length (builtins.concatMap (m: [ m (builtins.throw m) ]) [ "Marusja" ]))
|
(builtins.length (builtins.concatMap (m: [ m (builtins.throw m) ]) [ "Marusja" ]))
|
||||||
|
|
|
@ -3,20 +3,20 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
fix (self:
|
fix (self:
|
||||||
[
|
[
|
||||||
(builtins.typeOf null)
|
(builtins.typeOf null)
|
||||||
(builtins.typeOf true)
|
(builtins.typeOf true)
|
||||||
(builtins.typeOf (true && false))
|
(builtins.typeOf (true && false))
|
||||||
(builtins.typeOf 12)
|
(builtins.typeOf 12)
|
||||||
(builtins.typeOf (builtins.add 21 21))
|
(builtins.typeOf (builtins.add 21 21))
|
||||||
(builtins.typeOf 1.2)
|
(builtins.typeOf 1.2)
|
||||||
(builtins.typeOf "foo")
|
(builtins.typeOf "foo")
|
||||||
(builtins.typeOf "${"foo" + "bar"}baz")
|
(builtins.typeOf "${"foo" + "bar"}baz")
|
||||||
(builtins.typeOf {})
|
(builtins.typeOf { })
|
||||||
# (builtins.typeOf { foo.bar = 32; }.foo) # TODO: re-enable when nested keys are done
|
# (builtins.typeOf { foo.bar = 32; }.foo) # TODO: re-enable when nested keys are done
|
||||||
(builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; }))
|
(builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; }))
|
||||||
(builtins.typeOf self)
|
(builtins.typeOf self)
|
||||||
(builtins.typeOf fix)
|
(builtins.typeOf fix)
|
||||||
(builtins.typeOf /nix/store)
|
(builtins.typeOf /nix/store)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,13 +14,13 @@ in
|
||||||
(builtins.isFloat 1)
|
(builtins.isFloat 1)
|
||||||
(builtins.isFunction thunk)
|
(builtins.isFunction thunk)
|
||||||
(builtins.isFunction (thunk thunk))
|
(builtins.isFunction (thunk thunk))
|
||||||
(builtins.isFunction {})
|
(builtins.isFunction { })
|
||||||
(builtins.isInt 1)
|
(builtins.isInt 1)
|
||||||
(builtins.isInt (thunk 42))
|
(builtins.isInt (thunk 42))
|
||||||
(builtins.isInt 1.0)
|
(builtins.isInt 1.0)
|
||||||
(builtins.isList [ (throw "oh no") (abort "it's over") ])
|
(builtins.isList [ (throw "oh no") (abort "it's over") ])
|
||||||
(builtins.isList (thunk [ 21 21 ]))
|
(builtins.isList (thunk [ 21 21 ]))
|
||||||
(builtins.isList (thunk {}))
|
(builtins.isList (thunk { }))
|
||||||
(builtins.isNull null)
|
(builtins.isNull null)
|
||||||
(builtins.isNull (thunk null))
|
(builtins.isNull (thunk null))
|
||||||
(builtins.isNull 42)
|
(builtins.isNull 42)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval (builtins.intersectAttrs (throw "fred") {})).success
|
(builtins.tryEval (builtins.intersectAttrs (throw "fred") { })).success
|
||||||
|
|
|
@ -5,10 +5,10 @@ let
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
{ q = g "ia"; } == { q = g ("i"+"a"); }
|
{ q = g "ia"; } == { q = g ("i" + "a"); }
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
[ (g "ia") ] == [ (g ("i"+"a")) ]
|
[ (g "ia") ] == [ (g ("i" + "a")) ]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
# self-recursive function should be able to close over itself
|
# self-recursive function should be able to close over itself
|
||||||
f = n: if n <= 0 then "done" else f (n - 1);
|
f = n: if n <= 0 then "done" else f (n - 1);
|
||||||
in f 10
|
in
|
||||||
|
f 10
|
||||||
|
|
|
@ -8,7 +8,7 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
# introduce some closure depth to force both kinds of upvalue
|
# introduce some closure depth to force both kinds of upvalue
|
||||||
# resolution, and introduce a dynamically known `a` within the
|
# resolution, and introduce a dynamically known `a` within the
|
||||||
# closures
|
# closures
|
||||||
let f = b: with { a = 2; }; c: a + b + c;
|
let f = b: with { a = 2; }; c: a + b + c;
|
||||||
in f 0 0
|
in f 0 0
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
({ __toString = _: "lord"; } + "nikon")
|
({ __toString = _: "lord"; } + "nikon")
|
||||||
("zero" + { __toString = _: "cool"; })
|
("zero" + { __toString = _: "cool"; })
|
||||||
(/tmp/31337 + "h4x0r")
|
(/tmp/31337 + "h4x0r")
|
||||||
("foo" + { outPath="blah"; })
|
("foo" + { outPath = "blah"; })
|
||||||
({ outPath="blah"; } + "foo")
|
({ outPath = "blah"; } + "foo")
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
[
|
[
|
||||||
([1 2] < [1])
|
([ 1 2 ] < [ 1 ])
|
||||||
([1 2] < [2 3])
|
([ 1 2 ] < [ 2 3 ])
|
||||||
([1 2] < [2])
|
([ 1 2 ] < [ 2 ])
|
||||||
([1 2] < [1 2 3])
|
([ 1 2 ] < [ 1 2 3 ])
|
||||||
([3 4] < [1])
|
([ 3 4 ] < [ 1 ])
|
||||||
([1 2] > [1])
|
([ 1 2 ] > [ 1 ])
|
||||||
([1 2] > [2 3])
|
([ 1 2 ] > [ 2 3 ])
|
||||||
([1 2] > [2])
|
([ 1 2 ] > [ 2 ])
|
||||||
([1 2] > [1 2 3])
|
([ 1 2 ] > [ 1 2 3 ])
|
||||||
([3 4] > [1])
|
([ 3 4 ] > [ 1 ])
|
||||||
([1 2] <= [1])
|
([ 1 2 ] <= [ 1 ])
|
||||||
([1 2] >= [2 3])
|
([ 1 2 ] >= [ 2 3 ])
|
||||||
([1 2] >= [2])
|
([ 1 2 ] >= [ 2 ])
|
||||||
([1 2] <= [1 2 3])
|
([ 1 2 ] <= [ 1 2 3 ])
|
||||||
([3 4] >= [1])
|
([ 3 4 ] >= [ 1 ])
|
||||||
]
|
]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])
|
(builtins.concatMap (x: [ x ] ++ [ "z" ]) [ "a" "b" ])
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
with builtins;
|
with builtins;
|
||||||
|
|
||||||
[ (concatStringsSep "" [])
|
[
|
||||||
(concatStringsSep "" ["foo" "bar" "xyzzy"])
|
(concatStringsSep "" [ ])
|
||||||
(concatStringsSep ", " ["foo" "bar" "xyzzy"])
|
(concatStringsSep "" [ "foo" "bar" "xyzzy" ])
|
||||||
(concatStringsSep ", " ["foo"])
|
(concatStringsSep ", " [ "foo" "bar" "xyzzy" ])
|
||||||
(concatStringsSep ", " [])
|
(concatStringsSep ", " [ "foo" ])
|
||||||
|
(concatStringsSep ", " [ ])
|
||||||
]
|
]
|
||||||
|
|
|
@ -15,4 +15,7 @@ with { c = 3; d = 3; };
|
||||||
_:
|
_:
|
||||||
with { d = 4; };
|
with { d = 4; };
|
||||||
|
|
||||||
[ a b c d ]) null null null null
|
[ a b c d ]) null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
|
|
@ -5,4 +5,5 @@ let
|
||||||
set = {
|
set = {
|
||||||
value = 42;
|
value = 42;
|
||||||
};
|
};
|
||||||
in result
|
in
|
||||||
|
result
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[["f" ""]] == [["f" ""]]
|
[ [ "f" "" ] ] == [ [ "f" "" ] ]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval (builtins.elem { type = rec { x = throw "fred"; }.x; } [ { type = 3; } ])).success
|
(builtins.tryEval (builtins.elem { type = rec { x = throw "fred"; }.x; } [{ type = 3; }])).success
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
let
|
let
|
||||||
fib' = i: n: m: if i == 0
|
fib' = i: n: m:
|
||||||
|
if i == 0
|
||||||
then n
|
then n
|
||||||
else fib' (i - 1) m (n + m);
|
else fib' (i - 1) m (n + m);
|
||||||
|
|
||||||
fib = n: fib' n 1 1;
|
fib = n: fib' n 1 1;
|
||||||
in fib 10
|
in
|
||||||
|
fib 10
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
let
|
let
|
||||||
fix = f: let x = f x; in x;
|
fix = f: let x = f x; in x;
|
||||||
in fix(self: {
|
in
|
||||||
|
fix (self: {
|
||||||
a = 1;
|
a = 1;
|
||||||
b = self.a + 20;
|
b = self.a + 20;
|
||||||
c = self.b * 2;
|
c = self.b * 2;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[
|
[
|
||||||
(builtins.foldl' builtins.add 0 [1 2 3])
|
(builtins.foldl' builtins.add 0 [ 1 2 3 ])
|
||||||
(builtins.foldl' (l1: l2: l1 ++ l2) [0] [[1] [2 3]])
|
(builtins.foldl' (l1: l2: l1 ++ l2) [ 0 ] [ [ 1 ] [ 2 3 ] ])
|
||||||
(builtins.foldl' (x: y: if x == 0 then y else x * y) 0 [1 2])
|
(builtins.foldl' (x: y: if x == 0 then y else x * y) 0 [ 1 2 ])
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,7 +14,7 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
# Note that the crash did not occur if the offending expression was the rhs
|
# Note that the crash did not occur if the offending expression was the rhs
|
||||||
# argument to `builtins.seq`, hence we need to put the assert in between.
|
# argument to `builtins.seq`, hence we need to put the assert in between.
|
||||||
assert builtins.seq bomb true;
|
assert builtins.seq bomb true;
|
||||||
|
|
||||||
f { finalise = bomb; }
|
f { finalise = bomb; }
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
[
|
[
|
||||||
# RFC 7159, section 13.
|
# RFC 7159, section 13.
|
||||||
(builtins.fromJSON
|
(builtins.fromJSON
|
||||||
''
|
''
|
||||||
{
|
{
|
||||||
"Image": {
|
"Image": {
|
||||||
"Width": 800,
|
"Width": 800,
|
||||||
"Height": 600,
|
"Height": 600,
|
||||||
"Title": "View from 15th Floor",
|
"Title": "View from 15th Floor",
|
||||||
"Thumbnail": {
|
"Thumbnail": {
|
||||||
"Url": "http://www.example.com/image/481989943",
|
"Url": "http://www.example.com/image/481989943",
|
||||||
"Height": 125,
|
"Height": 125,
|
||||||
"Width": 100
|
"Width": 100
|
||||||
},
|
},
|
||||||
"Animated" : false,
|
"Animated" : false,
|
||||||
"IDs": [116, 943, 234, 38793, true ,false,null, -100],
|
"IDs": [116, 943, 234, 38793, true ,false,null, -100],
|
||||||
"Latitude": 37.7668,
|
"Latitude": 37.7668,
|
||||||
"Longitude": -122.396
|
"Longitude": -122.396
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
'')
|
||||||
'')
|
|
||||||
(builtins.fromJSON ''{"name": "a", "value": "b"}'')
|
(builtins.fromJSON ''{"name": "a", "value": "b"}'')
|
||||||
(builtins.fromJSON "[ 1, 2, 3, 4 ]")
|
(builtins.fromJSON "[ 1, 2, 3, 4 ]")
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
let
|
let
|
||||||
|
|
||||||
stdenvFun = { }: { name = "stdenv"; };
|
stdenvFun = {}: { name = "stdenv"; };
|
||||||
stdenv2Fun = { }: { name = "stdenv2"; };
|
stdenv2Fun = {}: { name = "stdenv2"; };
|
||||||
fetchurlFun = { stdenv }: assert stdenv.name == "stdenv"; { name = "fetchurl"; };
|
fetchurlFun = { stdenv }: assert stdenv.name == "stdenv"; { name = "fetchurl"; };
|
||||||
atermFun = { stdenv, fetchurl }: { name = "aterm-${stdenv.name}"; };
|
atermFun = { stdenv, fetchurl }: { name = "aterm-${stdenv.name}"; };
|
||||||
aterm2Fun = { stdenv, fetchurl }: { name = "aterm2-${stdenv.name}"; };
|
aterm2Fun = { stdenv, fetchurl }: { name = "aterm2-${stdenv.name}"; };
|
||||||
nixFun = { stdenv, fetchurl, aterm }: { name = "nix-${stdenv.name}-${aterm.name}"; };
|
nixFun = { stdenv, fetchurl, aterm }: { name = "nix-${stdenv.name}-${aterm.name}"; };
|
||||||
|
|
||||||
mplayerFun =
|
mplayerFun =
|
||||||
{ stdenv, fetchurl, enableX11 ? false, xorg ? null, enableFoo ? true, foo ? null }:
|
{ stdenv, fetchurl, enableX11 ? false, xorg ? null, enableFoo ? true, foo ? null }:
|
||||||
assert stdenv.name == "stdenv2";
|
assert stdenv.name == "stdenv2";
|
||||||
assert enableX11 -> xorg.libXv.name == "libXv";
|
assert enableX11 -> xorg.libXv.name == "libXv";
|
||||||
assert enableFoo -> foo != null;
|
assert enableFoo -> foo != null;
|
||||||
{ name = "mplayer-${stdenv.name}.${xorg.libXv.name}-${xorg.libX11.name}"; };
|
{ name = "mplayer-${stdenv.name}.${xorg.libXv.name}-${xorg.libX11.name}"; };
|
||||||
|
|
||||||
makeOverridable = f: origArgs: f origArgs //
|
makeOverridable = f: origArgs: f origArgs //
|
||||||
{ override = newArgs:
|
{
|
||||||
|
override = newArgs:
|
||||||
makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs));
|
makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,7 +38,8 @@ let
|
||||||
mplayer = callPackage mplayerFun { stdenv = pkgs.stdenv2; enableFoo = false; };
|
mplayer = callPackage mplayerFun { stdenv = pkgs.stdenv2; enableFoo = false; };
|
||||||
nix = callPackage nixFun { };
|
nix = callPackage nixFun { };
|
||||||
};
|
};
|
||||||
in pkgs;
|
in
|
||||||
|
pkgs;
|
||||||
|
|
||||||
libX11Fun = { stdenv, fetchurl }: { name = "libX11"; };
|
libX11Fun = { stdenv, fetchurl }: { name = "libX11"; };
|
||||||
libX11_2Fun = { stdenv, fetchurl }: { name = "libX11_2"; };
|
libX11_2Fun = { stdenv, fetchurl }: { name = "libX11_2"; };
|
||||||
|
@ -67,14 +69,15 @@ let
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
[ pkgs.stdenv.name
|
[
|
||||||
pkgs.fetchurl.name
|
pkgs.stdenv.name
|
||||||
pkgs.aterm.name
|
pkgs.fetchurl.name
|
||||||
pkgs2.aterm.name
|
pkgs.aterm.name
|
||||||
pkgs.xorg.libX11.name
|
pkgs2.aterm.name
|
||||||
pkgs.xorg.libXv.name
|
pkgs.xorg.libX11.name
|
||||||
pkgs.mplayer.name
|
pkgs.xorg.libXv.name
|
||||||
pkgs2.mplayer.name
|
pkgs.mplayer.name
|
||||||
pkgs.nix.name
|
pkgs2.mplayer.name
|
||||||
pkgs2.nix.name
|
pkgs.nix.name
|
||||||
]
|
pkgs2.nix.name
|
||||||
|
]
|
||||||
|
|
|
@ -4,4 +4,5 @@ let
|
||||||
set = {
|
set = {
|
||||||
inherit ({ value = 42; }) "value";
|
inherit ({ value = 42; }) "value";
|
||||||
};
|
};
|
||||||
in set.value
|
in
|
||||||
|
set.value
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
builtins.intersectAttrs
|
builtins.intersectAttrs
|
||||||
{ a = 1; b = 2; c = 3; }
|
{ a = 1; b = 2; c = 3; }
|
||||||
{ a = 100; b = 200; d = 5; }
|
{ a = 100; b = 200; d = 5; }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
f = n: n + a;
|
f = n: n + a;
|
||||||
a = 2;
|
a = 2;
|
||||||
in f 40
|
in
|
||||||
|
f 40
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
a = b;
|
a = b;
|
||||||
b = 42;
|
b = 42;
|
||||||
in a
|
in
|
||||||
|
a
|
||||||
|
|
|
@ -6,7 +6,8 @@ let
|
||||||
list3 = [ (2 + 2) ];
|
list3 = [ (2 + 2) ];
|
||||||
list4 = [ (2 + 2) ];
|
list4 = [ (2 + 2) ];
|
||||||
list5 = [ (2 + 2) ];
|
list5 = [ (2 + 2) ];
|
||||||
in [
|
in
|
||||||
|
[
|
||||||
(attrs1 == attrs2)
|
(attrs1 == attrs2)
|
||||||
(list1 == list2)
|
(list1 == list2)
|
||||||
(list3 == list2)
|
(list3 == list2)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
let {
|
let {
|
||||||
a = 21;
|
a = 21;
|
||||||
b = body.one;
|
b = body.one;
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
one = a * 2;
|
one = a * 2;
|
||||||
two = b;
|
two = b;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
with {}; let { body = 42; }
|
with { }; let { body = 42; }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
let {
|
let {
|
||||||
a = 21;
|
a = 21;
|
||||||
body = a * 2;
|
body = a * 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,5 @@ let
|
||||||
a = 1;
|
a = 1;
|
||||||
"b" = 2;
|
"b" = 2;
|
||||||
${"c"} = 3;
|
${"c"} = 3;
|
||||||
in [ a b c ]
|
in
|
||||||
|
[ a b c ]
|
||||||
|
|
|
@ -3,10 +3,11 @@ let
|
||||||
a = 1;
|
a = 1;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
let
|
let
|
||||||
set2 = {
|
set2 = {
|
||||||
b = 1;
|
b = 1;
|
||||||
};
|
};
|
||||||
inherit (set) a;
|
inherit (set) a;
|
||||||
inherit (set2) b;
|
inherit (set2) b;
|
||||||
in a + b
|
in
|
||||||
|
a + b
|
||||||
|
|
|
@ -2,4 +2,5 @@ let
|
||||||
a = 1;
|
a = 1;
|
||||||
b = 2;
|
b = 2;
|
||||||
c = a + b;
|
c = a + b;
|
||||||
in c
|
in
|
||||||
|
c
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[ 1 2 ] > [ ((rec{x=1;}).x) 2]
|
[ 1 2 ] > [ ((rec{ x = 1; }).x) 2 ]
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
with builtins;
|
with builtins;
|
||||||
let
|
let
|
||||||
fold = op: nul: list:
|
fold = op: nul: list:
|
||||||
if list == []
|
if list == [ ]
|
||||||
then nul
|
then nul
|
||||||
else op (head list) (fold op nul (tail list));
|
else op (head list) (fold op nul (tail list));
|
||||||
concat =
|
concat =
|
||||||
fold (x: y: x + y) "";
|
fold (x: y: x + y) "";
|
||||||
asi = name: value : { inherit name value; };
|
asi = name: value: { inherit name value; };
|
||||||
list = [ ( asi "a" "A" ) ( asi "b" "B" ) ];
|
list = [ (asi "a" "A") (asi "b" "B") ];
|
||||||
a = builtins.listToAttrs list;
|
a = builtins.listToAttrs list;
|
||||||
b = builtins.listToAttrs ( list ++ list );
|
b = builtins.listToAttrs (list ++ list);
|
||||||
r = builtins.listToAttrs [ (asi "result" [ a b ]) ( asi "throw" (throw "this should not be thrown")) ];
|
r = builtins.listToAttrs [ (asi "result" [ a b ]) (asi "throw" (throw "this should not be thrown")) ];
|
||||||
x = builtins.listToAttrs [ (asi "foo" "bar") (asi "foo" "bla") ];
|
x = builtins.listToAttrs [ (asi "foo" "bar") (asi "foo" "bla") ];
|
||||||
in concat (map (x: x.a) r.result) + x.foo
|
in
|
||||||
|
concat (map (x: x.a) r.result) + x.foo
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval ( (throw "fred") && (throw "jill") )).success
|
(builtins.tryEval ((throw "fred") && (throw "jill"))).success
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval ( (throw "fred") || (throw "jill") )).success
|
(builtins.tryEval ((throw "fred") || (throw "jill"))).success
|
||||||
|
|
|
@ -6,4 +6,5 @@ let
|
||||||
a = 21;
|
a = 21;
|
||||||
b = a * 2;
|
b = a * 2;
|
||||||
};
|
};
|
||||||
in set.b
|
in
|
||||||
|
set.b
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
let
|
let
|
||||||
doubler = n: outer n;
|
doubler = n: outer n;
|
||||||
outer = let inner = n: a * n;
|
outer =
|
||||||
a = 2;
|
let
|
||||||
in inner;
|
inner = n: a * n;
|
||||||
in doubler 10
|
a = 2;
|
||||||
|
in
|
||||||
|
inner;
|
||||||
|
in
|
||||||
|
doubler 10
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
inner = 21;
|
inner = 21;
|
||||||
set.a.b = inner * 2;
|
set.a.b = inner * 2;
|
||||||
in set
|
in
|
||||||
|
set
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
let
|
let
|
||||||
a = 1;
|
a = 1;
|
||||||
b = 2;
|
b = 2;
|
||||||
outer = let
|
outer =
|
||||||
c = 3;
|
let
|
||||||
d = 4;
|
c = 3;
|
||||||
inner = let
|
d = 4;
|
||||||
e = 5;
|
inner =
|
||||||
f = 6;
|
let
|
||||||
in g: [ a b c d e f g ];
|
e = 5;
|
||||||
in inner;
|
f = 6;
|
||||||
in outer 7
|
in
|
||||||
|
g: [ a b c d e f g ];
|
||||||
|
in
|
||||||
|
inner;
|
||||||
|
in
|
||||||
|
outer 7
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
let
|
let
|
||||||
a = let
|
a =
|
||||||
b = 1;
|
let
|
||||||
c = 2;
|
b = 1;
|
||||||
in b + c;
|
c = 2;
|
||||||
|
in
|
||||||
|
b + c;
|
||||||
b = 4;
|
b = 4;
|
||||||
in a + b
|
in
|
||||||
|
a + b
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
null = 1;
|
null = 1;
|
||||||
f = n: n + null;
|
f = n: n + null;
|
||||||
in f 41
|
in
|
||||||
|
f 41
|
||||||
|
|
|
@ -4,4 +4,5 @@ let
|
||||||
a = b;
|
a = b;
|
||||||
b = c;
|
b = c;
|
||||||
c = 42;
|
c = 42;
|
||||||
in a
|
in
|
||||||
|
a
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
set1 = { a = 1; };
|
set1 = { a = 1; };
|
||||||
set2 = { a = 2; };
|
set2 = { a = 2; };
|
||||||
in with set1; with set2; a
|
in
|
||||||
|
with set1; with set2; a
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
# the first dash followed by a non-alphabetic character separates
|
# the first dash followed by a non-alphabetic character separates
|
||||||
# the "name" from the "version"
|
# the "name" from the "version"
|
||||||
|
|
||||||
assert builtins.parseDrvName "ripgrep-1.2" == { name = "ripgrep"; version = "1.2"; };
|
assert builtins.parseDrvName "ripgrep-1.2" == { name = "ripgrep"; version = "1.2"; };
|
||||||
assert builtins.parseDrvName "rip-grep-1.2" == { name = "rip-grep"; version = "1.2"; };
|
assert builtins.parseDrvName "rip-grep-1.2" == { name = "rip-grep"; version = "1.2"; };
|
||||||
assert builtins.parseDrvName "7zip_archiver-0.2" == { name = "7zip_archiver"; version = "0.2"; };
|
assert builtins.parseDrvName "7zip_archiver-0.2" == { name = "7zip_archiver"; version = "0.2"; };
|
||||||
assert builtins.parseDrvName "gcc-1-2" == { name = "gcc"; version = "1-2"; };
|
assert builtins.parseDrvName "gcc-1-2" == { name = "gcc"; version = "1-2"; };
|
||||||
assert builtins.parseDrvName "bash--1-2" == { name = "bash"; version = "-1-2"; };
|
assert builtins.parseDrvName "bash--1-2" == { name = "bash"; version = "-1-2"; };
|
||||||
assert builtins.parseDrvName "xvidtune-?1-2" == { name = "xvidtune"; version = "?1-2"; };
|
assert builtins.parseDrvName "xvidtune-?1-2" == { name = "xvidtune"; version = "?1-2"; };
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
builtins.pathExists ./lib.nix
|
builtins.pathExists ./lib.nix
|
||||||
&& !builtins.pathExists ./bla.nix
|
&& !builtins.pathExists ./bla.nix
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
let {
|
let {
|
||||||
attrs = {x = 123; y = 456;};
|
attrs = { x = 123; y = 456; };
|
||||||
|
|
||||||
body = (removeAttrs attrs ["x"]).y;
|
body = (removeAttrs attrs [ "x" ]).y;
|
||||||
}
|
}
|
|
@ -3,11 +3,12 @@
|
||||||
let
|
let
|
||||||
inherit (builtins) foldl' listToAttrs;
|
inherit (builtins) foldl' listToAttrs;
|
||||||
|
|
||||||
input = [ { name = "result"; value = 1; } { name = "result"; value = 2; } ];
|
input = [{ name = "result"; value = 1; } { name = "result"; value = 2; }];
|
||||||
|
|
||||||
# foldl-based version of listToAttrs with the _opposite_ behaviour.
|
# foldl-based version of listToAttrs with the _opposite_ behaviour.
|
||||||
listToAttrs' = list: foldl' ( acc: elem: acc // { ${elem.name} = elem.value; }) {} list;
|
listToAttrs' = list: foldl' (acc: elem: acc // { ${elem.name} = elem.value; }) { } list;
|
||||||
in [
|
in
|
||||||
|
[
|
||||||
(listToAttrs input).result
|
(listToAttrs input).result
|
||||||
(listToAttrs' input).result
|
(listToAttrs' input).result
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
let
|
let
|
||||||
a = 1;
|
a = 1;
|
||||||
b = 2;
|
b = 2;
|
||||||
in a + b
|
in
|
||||||
|
a + b
|
||||||
|
|
|
@ -2,4 +2,5 @@ let
|
||||||
set = {
|
set = {
|
||||||
a = 1;
|
a = 1;
|
||||||
};
|
};
|
||||||
in with set; a
|
in
|
||||||
|
with set; a
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(builtins.tryEval ( builtins.substring 0 4 (throw "jill") )).success
|
(builtins.tryEval (builtins.substring 0 4 (throw "jill"))).success
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
let
|
let
|
||||||
__functor = f;
|
__functor = f;
|
||||||
f = self: x: self.out * x;
|
f = self: x: self.out * x;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
inherit __functor;
|
inherit __functor;
|
||||||
out = 21;
|
out = 21;
|
||||||
} 2
|
} 2
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
let
|
let
|
||||||
a = {};
|
a = { };
|
||||||
in let
|
in
|
||||||
|
let
|
||||||
c = if builtins.isFunction a then a b else a;
|
c = if builtins.isFunction a then a b else a;
|
||||||
b = {};
|
b = { };
|
||||||
in c
|
in
|
||||||
|
c
|
||||||
|
|
|
@ -4,4 +4,5 @@ let
|
||||||
set = {
|
set = {
|
||||||
a = with { b = 42; }; b;
|
a = with { b = 42; }; b;
|
||||||
};
|
};
|
||||||
in set.a
|
in
|
||||||
|
set.a
|
||||||
|
|
|
@ -5,6 +5,7 @@ let
|
||||||
a = 1;
|
a = 1;
|
||||||
b = 2;
|
b = 2;
|
||||||
c = 3;
|
c = 3;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
inherit a b c;
|
inherit a b c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
let
|
let
|
||||||
poisoned = let
|
poisoned =
|
||||||
true = 1;
|
let
|
||||||
false = 2;
|
true = 1;
|
||||||
null = 3;
|
false = 2;
|
||||||
in [ true false null ];
|
null = 3;
|
||||||
in [ true false null ] ++ poisoned
|
in
|
||||||
|
[ true false null ];
|
||||||
|
in
|
||||||
|
[ true false null ] ++ poisoned
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
# provide the value.
|
# provide the value.
|
||||||
|
|
||||||
# Provide a dynamic `x` identifier in the scope.
|
# Provide a dynamic `x` identifier in the scope.
|
||||||
with ({ x = 1;});
|
with ({ x = 1; });
|
||||||
|
|
||||||
# inherit this `x` as a static identifier
|
# inherit this `x` as a static identifier
|
||||||
let inherit x;
|
let inherit x;
|
||||||
|
|
||||||
# Provide another dynamic `x` identifier
|
# Provide another dynamic `x` identifier
|
||||||
in with ({ x = 3; });
|
in
|
||||||
|
with ({ x = 3; });
|
||||||
|
|
||||||
# Inherited static identifier should have precedence
|
# Inherited static identifier should have precedence
|
||||||
x
|
x
|
||||||
|
|
|
@ -9,4 +9,5 @@ let
|
||||||
${with set1; key} = 20;
|
${with set1; key} = 20;
|
||||||
${with { key = "c"; }; key} = 2;
|
${with { key = "c"; }; key} = 2;
|
||||||
};
|
};
|
||||||
in set2.a + set2.b + set2.c
|
in
|
||||||
|
set2.a + set2.b + set2.c
|
||||||
|
|
|
@ -6,7 +6,8 @@ let
|
||||||
set = {
|
set = {
|
||||||
value = 2;
|
value = 2;
|
||||||
};
|
};
|
||||||
in [
|
in
|
||||||
|
[
|
||||||
1
|
1
|
||||||
(with set; value)
|
(with set; value)
|
||||||
3
|
3
|
||||||
|
|
|
@ -3,7 +3,7 @@ with builtins;
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
fold = op: nul: list:
|
fold = op: nul: list:
|
||||||
if list == []
|
if list == [ ]
|
||||||
then nul
|
then nul
|
||||||
else op (head list) (fold op nul (tail list));
|
else op (head list) (fold op nul (tail list));
|
||||||
|
|
||||||
|
@ -14,23 +14,25 @@ rec {
|
||||||
|
|
||||||
flatten = x:
|
flatten = x:
|
||||||
if isList x
|
if isList x
|
||||||
then fold (x: y: (flatten x) ++ y) [] x
|
then fold (x: y: (flatten x) ++ y) [ ] x
|
||||||
else [x];
|
else [ x ];
|
||||||
|
|
||||||
sum = foldl' (x: y: add x y) 0;
|
sum = foldl' (x: y: add x y) 0;
|
||||||
|
|
||||||
hasSuffix = ext: fileName:
|
hasSuffix = ext: fileName:
|
||||||
let lenFileName = stringLength fileName;
|
let
|
||||||
lenExt = stringLength ext;
|
lenFileName = stringLength fileName;
|
||||||
in !(lessThan lenFileName lenExt) &&
|
lenExt = stringLength ext;
|
||||||
substring (sub lenFileName lenExt) lenFileName fileName == ext;
|
in
|
||||||
|
!(lessThan lenFileName lenExt) &&
|
||||||
|
substring (sub lenFileName lenExt) lenFileName fileName == ext;
|
||||||
|
|
||||||
# Split a list at the given position.
|
# Split a list at the given position.
|
||||||
splitAt = pos: list:
|
splitAt = pos: list:
|
||||||
if pos == 0 then {first = []; second = list;} else
|
if pos == 0 then { first = [ ]; second = list; } else
|
||||||
if list == [] then {first = []; second = [];} else
|
if list == [ ] then { first = [ ]; second = [ ]; } else
|
||||||
let res = splitAt (sub pos 1) (tail list);
|
let res = splitAt (sub pos 1) (tail list);
|
||||||
in {first = [(head list)] ++ res.first; second = res.second;};
|
in { first = [ (head list) ] ++ res.first; second = res.second; };
|
||||||
|
|
||||||
# Stable merge sort.
|
# Stable merge sort.
|
||||||
sortBy = comp: list:
|
sortBy = comp: list:
|
||||||
|
@ -40,14 +42,15 @@ rec {
|
||||||
split = splitAt (div (length list) 2) list;
|
split = splitAt (div (length list) 2) list;
|
||||||
first = sortBy comp split.first;
|
first = sortBy comp split.first;
|
||||||
second = sortBy comp split.second;
|
second = sortBy comp split.second;
|
||||||
in mergeLists comp first second
|
in
|
||||||
|
mergeLists comp first second
|
||||||
else list;
|
else list;
|
||||||
|
|
||||||
mergeLists = comp: list1: list2:
|
mergeLists = comp: list1: list2:
|
||||||
if list1 == [] then list2 else
|
if list1 == [ ] then list2 else
|
||||||
if list2 == [] then list1 else
|
if list2 == [ ] then list1 else
|
||||||
if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
|
if comp (head list2) (head list1) then [ (head list2) ] ++ mergeLists comp list1 (tail list2) else
|
||||||
[(head list1)] ++ mergeLists comp (tail list1) list2;
|
[ (head list1) ] ++ mergeLists comp (tail list1) list2;
|
||||||
|
|
||||||
id = x: x;
|
id = x: x;
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ rec {
|
||||||
|
|
||||||
range = first: last:
|
range = first: last:
|
||||||
if first > last
|
if first > last
|
||||||
then []
|
then [ ]
|
||||||
else genList (n: first + n) (last - first + 1);
|
else genList (n: first + n) (last - first + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
builtins.genericClosure {
|
builtins.genericClosure {
|
||||||
startSet = [ { key = id; first = true; } ];
|
startSet = [{ key = id; first = true; }];
|
||||||
operator =
|
operator =
|
||||||
{ first, ... }:
|
{ first, ... }:
|
||||||
if first then [
|
if first then [
|
||||||
{ key = id; first = false; }
|
{ key = id; first = false; }
|
||||||
] else [];
|
] else [ ];
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
multiTail = {
|
multiTail = {
|
||||||
val = 42;
|
val = 42;
|
||||||
tail1 = multiTail;
|
tail1 = multiTail;
|
||||||
tail2 = multiTail;
|
tail2 = multiTail;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
|
@ -10,23 +10,110 @@
|
||||||
let
|
let
|
||||||
# C++ Nix 2.3 builtins except valueSize which is removed in later versions
|
# C++ Nix 2.3 builtins except valueSize which is removed in later versions
|
||||||
minimalBuiltins = [
|
minimalBuiltins = [
|
||||||
"abort" "add" "addErrorContext" "all" "any" "appendContext" "attrNames"
|
"abort"
|
||||||
"attrValues" "baseNameOf" "bitAnd" "bitOr" "bitXor" "builtins" "catAttrs"
|
"add"
|
||||||
"compareVersions" "concatLists" "concatMap" "concatStringsSep"
|
"addErrorContext"
|
||||||
"currentSystem" "currentTime" "deepSeq" "derivation" "derivationStrict"
|
"all"
|
||||||
"dirOf" "div" "elem" "elemAt" "false" "fetchGit" "fetchMercurial"
|
"any"
|
||||||
"fetchTarball" "fetchurl" "filter" "filterSource" "findFile" "foldl'"
|
"appendContext"
|
||||||
"fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure" "getAttr"
|
"attrNames"
|
||||||
"getContext" "getEnv" "hasAttr" "hasContext" "hashFile" "hashString" "head"
|
"attrValues"
|
||||||
"import" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt"
|
"baseNameOf"
|
||||||
"isList" "isNull" "isPath" "isString" "langVersion" "length" "lessThan"
|
"bitAnd"
|
||||||
"listToAttrs" "map" "mapAttrs" "match" "mul" "nixPath" "nixVersion" "null"
|
"bitOr"
|
||||||
"parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir"
|
"bitXor"
|
||||||
"readFile" "removeAttrs" "replaceStrings" "scopedImport" "seq" "sort"
|
"builtins"
|
||||||
"split" "splitVersion" "storeDir" "storePath" "stringLength" "sub"
|
"catAttrs"
|
||||||
"substring" "tail" "throw" "toFile" "toJSON" "toPath" "toString" "toXML"
|
"compareVersions"
|
||||||
"trace" "true" "tryEval" "typeOf" "unsafeDiscardOutputDependency"
|
"concatLists"
|
||||||
"unsafeDiscardStringContext" "unsafeGetAttrPos"
|
"concatMap"
|
||||||
|
"concatStringsSep"
|
||||||
|
"currentSystem"
|
||||||
|
"currentTime"
|
||||||
|
"deepSeq"
|
||||||
|
"derivation"
|
||||||
|
"derivationStrict"
|
||||||
|
"dirOf"
|
||||||
|
"div"
|
||||||
|
"elem"
|
||||||
|
"elemAt"
|
||||||
|
"false"
|
||||||
|
"fetchGit"
|
||||||
|
"fetchMercurial"
|
||||||
|
"fetchTarball"
|
||||||
|
"fetchurl"
|
||||||
|
"filter"
|
||||||
|
"filterSource"
|
||||||
|
"findFile"
|
||||||
|
"foldl'"
|
||||||
|
"fromJSON"
|
||||||
|
"fromTOML"
|
||||||
|
"functionArgs"
|
||||||
|
"genList"
|
||||||
|
"genericClosure"
|
||||||
|
"getAttr"
|
||||||
|
"getContext"
|
||||||
|
"getEnv"
|
||||||
|
"hasAttr"
|
||||||
|
"hasContext"
|
||||||
|
"hashFile"
|
||||||
|
"hashString"
|
||||||
|
"head"
|
||||||
|
"import"
|
||||||
|
"intersectAttrs"
|
||||||
|
"isAttrs"
|
||||||
|
"isBool"
|
||||||
|
"isFloat"
|
||||||
|
"isFunction"
|
||||||
|
"isInt"
|
||||||
|
"isList"
|
||||||
|
"isNull"
|
||||||
|
"isPath"
|
||||||
|
"isString"
|
||||||
|
"langVersion"
|
||||||
|
"length"
|
||||||
|
"lessThan"
|
||||||
|
"listToAttrs"
|
||||||
|
"map"
|
||||||
|
"mapAttrs"
|
||||||
|
"match"
|
||||||
|
"mul"
|
||||||
|
"nixPath"
|
||||||
|
"nixVersion"
|
||||||
|
"null"
|
||||||
|
"parseDrvName"
|
||||||
|
"partition"
|
||||||
|
"path"
|
||||||
|
"pathExists"
|
||||||
|
"placeholder"
|
||||||
|
"readDir"
|
||||||
|
"readFile"
|
||||||
|
"removeAttrs"
|
||||||
|
"replaceStrings"
|
||||||
|
"scopedImport"
|
||||||
|
"seq"
|
||||||
|
"sort"
|
||||||
|
"split"
|
||||||
|
"splitVersion"
|
||||||
|
"storeDir"
|
||||||
|
"storePath"
|
||||||
|
"stringLength"
|
||||||
|
"sub"
|
||||||
|
"substring"
|
||||||
|
"tail"
|
||||||
|
"throw"
|
||||||
|
"toFile"
|
||||||
|
"toJSON"
|
||||||
|
"toPath"
|
||||||
|
"toString"
|
||||||
|
"toXML"
|
||||||
|
"trace"
|
||||||
|
"true"
|
||||||
|
"tryEval"
|
||||||
|
"typeOf"
|
||||||
|
"unsafeDiscardOutputDependency"
|
||||||
|
"unsafeDiscardStringContext"
|
||||||
|
"unsafeGetAttrPos"
|
||||||
];
|
];
|
||||||
|
|
||||||
intersectLists = as: bs: builtins.filter (a: builtins.elem a bs) as;
|
intersectLists = as: bs: builtins.filter (a: builtins.elem a bs) as;
|
||||||
|
|
Loading…
Reference in a new issue