-
-
Notifications
You must be signed in to change notification settings - Fork 277
Elaborate on let
bindings
#867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The original documentation says let bindings are for "repeated use", though one can run ```nix a = 3; a + a ``` just fine without the binding. I think it's more appropriate to explain that `let` limits how far a value's name can reach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to nix.dev, @rayhem! It's great to see new users and contributors joining our community.
Thank you for your suggestions regarding the language tutorial. This section of the site has been crafted with a lot of care, and we're always mindful about maintaining its conciseness to respect our readers' time and attention. While we might not make significant changes to this part right now, your input is still valued and definitely contributes to our ongoing discussions.
Please continue to explore nix.dev and don't hesitate to share more issues and PRs. Your perspective is important to us, and there's a lot of room for improvement and new ideas. Your engagement is what helps our community grow and thrive. Looking forward to seeing more of your contributions!
source/tutorials/nix-language.md
Outdated
Attempting to use the value outside of the binding produces an error: | ||
|
||
```{code-block} nix | ||
:class: expression | ||
a | ||
``` | ||
|
||
```{code-block} | ||
:class: value | ||
error: undefined variable 'a' | ||
|
||
at «string»:1:1: | ||
|
||
1| a | ||
| ^ | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that this section is a bit redundant, as it's only showing that we can't refer to a variable that hasn't been defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Do you think it would be appropriate to add commentary along the lines of "let
is similar to curly brace scoping in other languages" with information on the similarities and differences? Or is that too much for this section of the tutorial?
Co-authored-by: Henrik <[email protected]>
That only works in the nix repl (although only if you remove the let
a = 3;
in
a + a |
@rayhem Sorry for chiming in late. Indeed I think it would be too much to go into that sort of depth here. The tutorial is supposed to be a first, deliberately superficial introduction to the most widely used patterns. And yet some readers report it hits them like a wall of text. So while there needs to be a place for these different angles on the language, it would probably need to be a separate tutorial: #579 (And there probably needs to be an even more condensed first glance at the language.) Since the change now seems to have boiled down to almost nothing, I'll close this PR. This is not to dismiss your work! Feel free to add your feedback to other issues as we compile ideas for further tutorials and guides. |
The original documentation says let bindings are for "repeated use", though one can run
just fine without the binding. I think it's more appropriate to explain that
let
limits how far a value's name can reach. This is mentioned later, though, so I'm kind of puzzled on how to improve the language here and make it obvious why a let binding is a useful construction right up front.