tazjin / nix-1p

A (more or less) one page introduction to Nix, the language.
https://code.tvl.fyi/about/nix/nix-1p
896 stars 24 forks source link

Provide a statement about how whitespace is interpreted in Nix code. #22

Open WayneSherman opened 7 months ago

WayneSherman commented 7 months ago

In code formatting, is whitespace meaningful? Does the syntax depend on line breaks in any way?

For example, the first time functions are introduced, the full declaration is on one line: https://github.com/tazjin/nix-1p/blob/1cf10d3fb78d2500ea46640492e0a92aeda5fe69/README.md?plain=1#L196

Later an example function declaration takes up 3 lines with a blank line in between: https://github.com/tazjin/nix-1p/blob/1cf10d3fb78d2500ea46640492e0a92aeda5fe69/README.md?plain=1#L562-L564

ChatGPT: "In the Nix language, whitespace is generally used to separate tokens but does not have a significant impact on the interpretation of code beyond this. Unlike some programming languages where indentation or the presence of whitespace can alter the behavior of the code, Nix treats extra spaces, line breaks, and indentation as non-semantic, primarily for improving code readability and organization."