From f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Sun, 24 May 2009 10:57:41 +0000 Subject: big breaking change: renaming lib.getAttr to lib.attrByPath getAttr was ambiguous. It's also a builtin function fix svn path=/nixpkgs/trunk/; revision=15692 --- pkgs/lib/attrsets.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'pkgs/lib/attrsets.nix') diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 1348a15bdba..1d3cabe6f1b 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -12,21 +12,24 @@ rec { /* Return an attribute from nested attribute sets. For instance ["x" "y"] applied to some set e returns e.x.y, if it exists. The - default value is returned otherwise. !!! there is also - builtins.getAttr (is there a better name for this function?) - */ - getAttr = attrPath: default: e: + default value is returned otherwise. */ + attrByPath = attrPath: default: e: let attr = head attrPath; in if attrPath == [] then e else if builtins ? hasAttr && hasAttr attr e - then getAttr (tail attrPath) default (builtins.getAttr attr e) + then attrByPath (tail attrPath) default (builtins.getAttr attr e) else default; + # keep compatibility for some time. will be removed soon (the name getAttr + # should only be used for the builtins primop) + getAttr = a : b : c : builtins.trace "depreceated usage of lib.getAttr!" + (attrByPath a b c); + getAttrFromPath = attrPath: set: let errorMsg = "cannot find attribute `" + concatStringsSep "." attrPath + "'"; - in getAttr attrPath (abort errorMsg) set; + in attrByPath attrPath (abort errorMsg) set; /* Return the specified attributes from a set. -- cgit 1.4.1