Skip to content

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

Closed
wants to merge 3 commits into from
Closed

Elaborate on let bindings #867

wants to merge 3 commits into from

Conversation

rayhem
Copy link
Member

@rayhem rayhem commented Jan 21, 2024

The original documentation says let bindings are for "repeated use", though one can run

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. 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.

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.
@rayhem rayhem requested a review from a team January 21, 2024 03:26
Copy link
Contributor

@henrik-ch henrik-ch left a 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!

Comment on lines 391 to 408
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
| ^
```


Copy link
Contributor

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.

Copy link
Member Author

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?

@infinisil
Copy link
Member

The original documentation says let bindings are for "repeated use", though one can run

a = 3;
a + a

just fine without the binding.

That only works in the nix repl (although only if you remove the ;), it's not part of the Nix language per se! Underneath, nix repl roughly translates those statements into a Nix expression like this:

let
  a = 3;
in
a + a

@fricklerhandwerk
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants