[Nix-dev] Small Question on Strings, Attributes & Functions

Matan Shenhav matan at fluxcraft.net
Wed Aug 24 12:11:50 CEST 2016


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




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160824/8dcd8278/attachment.html>


More information about the nix-dev mailing list