4 ms·
Nixlang is so alien that I've used NixOS for 2 years and still don't get it. Nickel looks much prettier than Nixlang, but it carries over a feature that still
by notfed 4y ago
Nixlang is so alien that I've used NixOS for 2 years and still don't get it.
Nickel looks much prettier than Nixlang, but it carries over a feature that still confuses me about Nixlang: variable declaration. Perhaps you can shed light on why it is the way it is.
Why does it need to be of the format "let x = 5 in whatever(x);"? Why not, like Rust/F#/etc, allow the syntax "let x = 5; whatever(x)", i.e., allow the definition to stay in scope for the remainder of current block?
- Smaug123 4y agoI can only speculate, but I presume this is a historical detail from Standard ML.
- grumbel 4y agoEverything in Nix evaluates to a single value, including 'let' and even complete files. There are no blocks like in an imperative language. The '{}' in Nix are not blocks, but sets, known in other languages as maps or dicts. Thus what comes after the 'in' in a 'let' is an expression itself and has to return a single value. Meaning whenever you see a 'let', look at the surrounding, it will probably look like '{ a = (let x = 5; in x); }' which is just a convoluted way to write '{ a = 5; }'. Or often you'll see 'a = (foo: let ...)' in this case the ':' declares a function taking the argument 'foo'. You can play around with the language in the 'nix repl'. The language itself is really simple, but not very obvious when just looking at a code snippet it. And yes, there is an argument to be made that a purely expression based language is not very ergonomic, but it keeps the Nix language simple.