summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2009-05-24 10:57:46 +0000
committerMarc Weber <marco-oweber@gmx.de>2009-05-24 10:57:46 +0000
commit3157bb1098ca2bb16e793ec9946885562e3a4e10 (patch)
treeb8790ac877c6ea641cceee79c82c241be60eab8c /pkgs/lib
parentf7f938a1d15277fa11a2cbf75fe9c7d4344f25c3 (diff)
downloadnixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar.gz
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar.bz2
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar.lz
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar.xz
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.tar.zst
nixpkgs-3157bb1098ca2bb16e793ec9946885562e3a4e10.zip
removed all __primops from nixpkgs
svn path=/nixpkgs/trunk/; revision=15693
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/debug.nix20
-rw-r--r--pkgs/lib/misc.nix41
-rw-r--r--pkgs/lib/strings.nix14
-rw-r--r--pkgs/lib/tests.nix7
4 files changed, 47 insertions, 35 deletions
diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix
index a58539ee3c4..18b5e1db9d4 100644
--- a/pkgs/lib/debug.nix
+++ b/pkgs/lib/debug.nix
@@ -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));
diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix
index d515158c00a..a8f37ec277b 100644
--- a/pkgs/lib/misc.nix
+++ b/pkgs/lib/misc.nix
@@ -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 !
 }
diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix
index 9c045e9ae53..c1ce5d09757 100644
--- a/pkgs/lib/strings.nix
+++ b/pkgs/lib/strings.nix
@@ -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
diff --git a/pkgs/lib/tests.nix b/pkgs/lib/tests.nix
index 395b4b3e17b..95933cbe4b7 100644
--- a/pkgs/lib/tests.nix
+++ b/pkgs/lib/tests.nix
@@ -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