Overview of the Nix Language: Difference between revisions
imported>Kzvi No edit summary |
imported>Malteneuss m Improve Strings, Lists and Sets examples |
||
Line 51: | Line 51: | ||
! Type !! Description !! Example | ! Type !! Description !! Example | ||
|- | |- | ||
| Strings || Strings either start with <code>double quotes</code> or <code>double single quotes</code>. They also support antiquotation (templating). Leading spaces are stripped with double single quotes. || <code>"Say ${pkgs.hello.name}"</code> | | Strings || Strings either start with <code>double quotes</code> or <code>double single quotes</code>. They also support antiquotation (templating). Leading spaces are stripped with double single quotes. || <code>"Say ${pkgs.hello.name}"</code> | ||
Multiline String: | |||
<syntaxHighlight lang="nix">''first line | <syntaxHighlight lang="nix">''first line | ||
second line | second line | ||
Line 68: | Line 69: | ||
| URI || || <code>http://example.org/foo.tar.bz2</code> | | URI || || <code>http://example.org/foo.tar.bz2</code> | ||
|- | |- | ||
| Boolean || || <code>true</code>,<code>false</code> | | Boolean || || <code>true</code>, <code>false</code> | ||
|- | |- | ||
| Null || || <code>null</code> | | Null || || <code>null</code> | ||
|- | |- | ||
| Lists || items are | | Lists || items are separated by space, not comma. Each item can be a value of any other type || <syntaxHighlight lang=nix>[ 1 ./example.bin { hello="world"; }] </syntaxHighlight> | ||
|- | |- | ||
| Sets || In other languages called <code>dicts</code>(py),<code>objects</code>(js) <code>hashes</code>(ruby), essentially a list of key-value pairs || <syntaxHighlight lang=nix>{ hello="world"; }.hello | | Sets || In other languages called <code>dicts</code>(py),<code>objects</code>(js) <code>hashes</code>(ruby), essentially a list of key-value pairs || <syntaxHighlight lang=nix>{ key1="value1"; key2="value2"; }</syntaxHighlight> | ||
Access values through dot-notation:<syntaxHighlight lang=nix>{ hello="world"; }.hello | |||
> "world"</syntaxHighlight> | > "world"</syntaxHighlight> | ||
|- | |- |