Closed WayneSherman closed 7 months ago
let
absolutely is an expression that returns a value! A let
consists of the binding declarations, and the body (after in
, when using modern Nix). Evaluating this returns a value (the body with the bindings in place). This is referentially transparent and there is nothing sequential going on, i.e. there are no statements.
A directive here is meant to be any well-formed snippet of Nix code. I think you're confusing the lexical level (which tokens exist) with the semantic level (what does the parser construct out of the tokens), and I'm not sure how to make that clearer.
A suggestion to clarify this statement:
Everything in Nix is an expression meaning that every directive returns some kind of data.
Every well-formed (i.e. syntactically correct) block of code in Nix is an expression that returns a value.
("Well-formed" and "Syntactically correct" mean the block of code is syntactically complete and the structure, syntax, and order of elements adhere to the defined rules of the language.)
Alternatives to "block of code": "unit of code" "code segment"
How about a slightly simpler
Any valid piece of Nix code is [...]
?
I think that "well-formed" != "syntactically correct", as you can write syntactically correct code that fails to evaluate (e.g. builtins.add {} {}
)
How about a slightly simpler
Any valid piece of Nix code is [...]
Yes I think that is an improvement.
Making the change here: https://cl.tvl.fyi/c/depot/+/10737
"Everything in Nix is an expression"
There are parts of the language that are not expressions. For example, "Let" could be described as a "keyword" since it is a predefined reserved word in the Nix language. Although "Let" is "in Nix", it isn't an expression by itself. There are syntactical elements which are also part of Nix, but they are not expressions. For example "[" is a valid part of the Nix language, but not an expression by itself. In the Nix repl, if I type "Let" (and then enter) or "[" (and then enter) I get error messages."meaning that every directive returns some kind of data."
What is a "directive"?