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

Confusing what the scope of `with` is. #13

Closed fdietze closed 1 year ago

fdietze commented 1 year ago

In https://github.com/tazjin/nix-1p#with-statements

For me, it was a bit confusing what kind of thing with is. What I understood from the current explanation in my own words:

with <attr> is an expression which can precede an expression to put all members of into its scope:

nix-repl> let x = 7; attr = {a = 5;}; in x + (with attr; a)
12

However from my experiments with the repl, it only looks like an expression (because it is followed by ;), but it is not.

tazjin commented 1 year ago

Do you think this change would clarify it? https://cl.tvl.fyi/c/depot/+/8951/

fdietze commented 1 year ago

This looks better, thank you!