Hey,

I was going through the awesome and illuminating Tour of Nix when I bumped into 
a conundrum in doing exercise 33.


The 'pick' function is meant to return - in a list - the value of attribute 
'at' in attribute set 'attset':
pick = at: attset: if (attset ? at) then [ attset.at ] else []


 Testing this in the nix-repl yields:> testset = {a=1;}
> pick "a" testset
> [ ]

 Now having checked the solution of the exercise, I found that the following 
did work:
pick2 = at: attset: if (attset ? ${at}) then [ attset.${at} ] else []
> pick2 "a" testset
> [ 1 ]
 Additionally manual substitution worked:
> if testset ? "a" then [ testset."a" ] else []
> [ 1 ]
 Could someone kindly explain to me why 'pick2' and manual substitution work 
but 'pick' doesn't?


Cheers,
Matan





 * * * * *

Matan Bendix Shenhav
Chief Science Officer
Fluxcraft
+358 (0)45 6 135 315




_______________________________________________
nix-dev mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to