Nix Language Quirks: Difference between revisions

Imports and namespaces: Reword and link to relevant with/import links. Also removed the last part about let binding inherit priority and different "types" of inherit, because it was completely wrong/misleading afaik
Add example of using fromTOML for parsing hex/octal/binary number formats
Line 200: Line 200:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{ a = "b"; } // (if true then { foo = "bar"; } else { } )
{ a = "b"; } // (if true then { foo = "bar"; } else { } )
</syntaxHighlight>
== Hexadecimal, octal, and binary ==
As of late 2024, Nix doesn't contain builtin support for parsing many number formats like hexadecimal, octal, and binary. It ''does'', however, support the [https://noogle.dev/f/builtins/fromTOML <code>builtins.fromTOML</code>] function, which [https://github.com/NixOS/nix/issues/7578#issuecomment-1955985859 can be used] to parse these number formats.
<syntaxHighlight lang=nix>
nix-repl> (builtins.fromTOML "octal = 0o11").octal
9
nix-repl> (builtins.fromTOML "binary = 0b1001").binary
9
nix-repl> (builtins.fromTOML "hex = 0x09").hex       
9
</syntaxHighlight>
</syntaxHighlight>