Nix (language): Difference between revisions

imported>Vincentbernat
"@" pattern captures all arguments, not only the extra ones
imported>Pdinges
m Fix minor typos.
Line 98: Line 98:
==== Destructuring ====
==== Destructuring ====


In nix it happens that sets are given as arguments to functions. Say that we declare a function which returns the concatination of attributes a and b of a set like:
In nix it happens that sets are given as arguments to functions. Say that we declare a function which returns the concatenation of attributes a and b of a set like:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
concat_a_and_b =  set: set.a + set.b  
concat_a_and_b =  set: set.a + set.b  
Line 397: Line 397:
==== <code>let ... in</code> statement ====
==== <code>let ... in</code> statement ====


With <code>let</code> you can define local variables which can also reference to self without the need of the <code>rec</code> construct. This feature is use inside expressions to prepare variables which become part of an output.
With <code>let</code> you can define local variables which can also reference to self without the need of the <code>rec</code> construct. This feature is used inside expressions to prepare variables which become part of an output.
The usage of <code>let</code> is comparable to the [http://zvon.org/other/haskell/Outputsyntax/letQexpressions_reference.html Haskell let expression]
The usage of <code>let</code> is comparable to the [http://zvon.org/other/haskell/Outputsyntax/letQexpressions_reference.html Haskell let expression]
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>