Nix Language Quirks: Difference between revisions

imported>Fstamour
m typo
imported>Anton-Latukha
add info on replaceString matching ""
Line 91: Line 91:
error: attribute ‘x’ at (string):1:31 already defined at (string):1:24 </syntaxHighlight>
error: attribute ‘x’ at (string):1:31 already defined at (string):1:24 </syntaxHighlight>
This makes it a sane citizen of Nix lanugage... except it has a twin, called <code>{ inherit ...; }</code>. They DON'T do the same - <code>let inherit ...</code> adds let-bindings, and <code>{ inherit ...; }</code> adds attributes to a record.
This makes it a sane citizen of Nix lanugage... except it has a twin, called <code>{ inherit ...; }</code>. They DON'T do the same - <code>let inherit ...</code> adds let-bindings, and <code>{ inherit ...; }</code> adds attributes to a record.
== builtin.replaceStrings key match on "" ==
Syntax:
<syntaxHighlight lang=nix>
builtins.replaceStrings [match] [replace] string
</syntaxHighlight>
Function allows match for "" in string. <code>[match]</code> gets checked sequentially, and when "" is checked - it always matches. And so - when "" is checked in always inserts the replacement, then next char in sting gets passed through, and the next char after that from the string gets processed.
<syntaxHighlight lang=nix>
nix-repl> builtins.replaceStrings ["" "e"] [" " "i"] "Hello world"
" H e l l o  w o r l d "
nix-repl> builtins.replaceStrings ["ll" ""] [" " "i"] "Hello world"
"iHie ioi iwioirilidi"
</syntaxHighlight>


== Nix Language FAQ ==
== Nix Language FAQ ==