removed all __primops from nixpkgs

svn path=/nixpkgs/trunk/; revision=15693
This commit is contained in:
Marc Weber
2009-05-24 10:57:46 +00:00
parent f7f938a1d1
commit 3157bb1098
12 changed files with 66 additions and 50 deletions

View File

@@ -1,4 +1,8 @@
let lib = import ./default.nix; in
let lib = import ./default.nix;
inherit (builtins) trace attrNamesToStr isAttrs isFunction isList head substring attrNames;
in
rec {
@@ -20,20 +24,20 @@ rec {
# this can help debug your code as well - designed to not produce thousands of lines
traceShowVal = x : __trace (showVal x) x;
traceShowValMarked = str: x: __trace (str + showVal x) x;
attrNamesToStr = a : lib.concatStringsSep "; " (map (x : "${x}=") (__attrNames a));
traceShowVal = x : trace (showVal x) x;
traceShowValMarked = str: x: trace (str + showVal x) x;
attrNamesToStr = a : lib.concatStringsSep "; " (map (x : "${x}=") (attrNames a));
showVal = x :
if __isAttrs x then
if isAttrs x then
if x ? outPath then "x is a derivation, name ${if x ? name then x.name else "<no name>"}, { ${attrNamesToStr x} }"
else "x is attr set { ${attrNamesToStr x} }"
else if __isFunction x then "x is a function"
else if isFunction x then "x is a function"
else if x == [] then "x is an empty list"
else if __isList x then "x is a list, first item is : ${showVal (__head x)}"
else if isList x then "x is a list, first item is : ${showVal (head x)}"
else if x == true then "x is boolean true"
else if x == false then "x is boolean false"
else if x == null then "x is null"
else "x is probably a string starting, starting characters: ${__substring 0 50 x}..";
else "x is probably a string starting, starting characters: ${substring 0 50 x}..";
# trace the arguments passed to function and its result
traceCall = n : f : a : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a));
traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));

View File

@@ -1,4 +1,7 @@
let lib = import ./default.nix; in
let lib = import ./default.nix;
inherit (builtins) isFunction hasAttr getAttr head tail isList isAttrs attrNames;
in
with import ./lists.nix;
with import ./attrsets.nix;
@@ -53,7 +56,7 @@ rec {
f : # the function applied to the arguments
initial : # you pass attrs, the functions below are passing a function taking the fix argument
let
takeFixed = if (__isFunction initial) then initial else (fixed : initial); # transform initial to an expression always taking the fixed argument
takeFixed = if (isFunction initial) then initial else (fixed : initial); # transform initial to an expression always taking the fixed argument
tidy = args :
let # apply all functions given in "applyPreTidy" in sequence
applyPreTidyFun = fold ( n : a : x : n ( a x ) ) lib.id (maybeAttr "applyPreTidy" [] args);
@@ -61,9 +64,9 @@ rec {
fun = n : x :
let newArgs = fixed :
let args = takeFixed fixed;
mergeFun = __getAttr n args;
in if __isAttrs x then (mergeFun args x)
else assert __isFunction x;
mergeFun = getAttr n args;
in if isAttrs x then (mergeFun args x)
else assert isFunction x;
mergeFun args (x ( args // { inherit fixed; }));
in overridableDelayableArgs f newArgs;
in
@@ -302,15 +305,15 @@ rec {
fold lib.mergeAttrs {} [
x y
(mapAttrs ( a : v : # merge special names using given functions
if (__hasAttr a x)
then if (__hasAttr a y)
then v (__getAttr a x) (__getAttr a y) # both have attr, use merge func
else (__getAttr a x) # only x has attr
else (__getAttr a y) # only y has attr)
if (hasAttr a x)
then if (hasAttr a y)
then v (getAttr a x) (getAttr a y) # both have attr, use merge func
else (getAttr a x) # only x has attr
else (getAttr a y) # only y has attr)
) (removeAttrs mergeAttrBy2
# don't merge attrs which are neither in x nor y
(filter (a : (! __hasAttr a x) && (! __hasAttr a y) )
(__attrNames mergeAttrBy2))
(filter (a : (! hasAttr a x) && (! hasAttr a y) )
(attrNames mergeAttrBy2))
)
)
];
@@ -326,8 +329,8 @@ rec {
# pick attrs subset_attr_names and apply f
subsetmap = f : attrs : subset_attr_names :
listToAttrs (fold ( attr : r : if __hasAttr attr attrs
then r ++ [ ( nameValuePair attr ( f (__getAttr attr attrs) ) ) ] else r ) []
listToAttrs (fold ( attr : r : if hasAttr attr attrs
then r ++ [ ( nameValuePair attr ( f (getAttr attr attrs) ) ) ] else r ) []
subset_attr_names );
# prepareDerivationArgs tries to make writing configurable derivations easier
@@ -371,7 +374,7 @@ rec {
// args2.cfg;
opts = flattenAttrs (mapAttrs (a : v :
let v2 = if (v ? set || v ? unset) then v else { set = v; };
n = if (__getAttr (flagName a) cfgWithDefaults) then "set" else "unset";
n = if (getAttr (flagName a) cfgWithDefaults) then "set" else "unset";
attr = maybeAttr n {} v2; in
if (maybeAttr "assertion" true attr)
then attr
@@ -387,11 +390,11 @@ rec {
let eqListStrict = a : b :
if (a == []) != (b == []) then false
else if a == [] then true
else eqStrict (__head a) (__head b) && eqListStrict (__tail a) (__tail b);
else eqStrict (head a) (head b) && eqListStrict (tail a) (tail b);
in
if __isList a && __isList b then eqListStrict a b
else if __isAttrs a && isAttrs b then
(eqListStrict (__attrNames a) (__attrNames b))
if isList a && isList b then eqListStrict a b
else if isAttrs a && isAttrs b then
(eqListStrict (attrNames a) (attrNames b))
&& (eqListStrict (lib.attrValues a) (lib.attrValues b))
else a == b; # FIXME !
}

View File

@@ -1,6 +1,10 @@
/* String manipulation functions. */
let lib = import ./default.nix; in
let lib = import ./default.nix;
inherit (builtins) substring add sub stringLength;
in
rec {
inherit (builtins) stringLength substring head tail lessThan sub;
@@ -86,10 +90,10 @@ rec {
if s == "" then "" else
let takeTillSlash = left : c : s :
if left == 0 then s
else if (__substring left 1 s == "/") then
(__substring (__add left 1) (__sub c 1) s)
else takeTillSlash (__sub left 1) (__add c 1) s; in
takeTillSlash (__sub (__stringLength s) 1) 1 s;
else if (substring left 1 s == "/") then
(substring (add left 1) (sub c 1) s)
else takeTillSlash (sub left 1) (add c 1) s; in
takeTillSlash (sub (stringLength s) 1) 1 s;
# Compares strings not requiring context equality
# Obviously, a workaround but works on all Nix versions

View File

@@ -1,3 +1,4 @@
let inherit (builtins) add; in
with import ./default.nix;
runTests {
@@ -69,14 +70,14 @@ runTests {
res4 = let x = defaultOverridableDelayableArgs id { a = 7; };
in (x.merge) ( x: { b = 10; });
res5 = let x = defaultOverridableDelayableArgs id { a = 7; };
in (x.merge) ( x: { a = __add x.a 3; });
res6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = __add; }; };
in (x.merge) ( x: { a = add x.a 3; });
res6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = add; }; };
y = x.merge {};
in (y.merge) { a = 10; };
resRem7 = res6.replace (a : removeAttrs a ["a"]);
resReplace6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = __add; }; };
resReplace6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = add; }; };
x2 = x.merge { a = 20; }; # now we have 27
in (x2.replace) { a = 10; }; # and override the value by 10