Skip to content
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

Syntax question: to let or not to let #217

Closed
nikomatsakis opened this issue Oct 3, 2022 · 6 comments
Closed

Syntax question: to let or not to let #217

nikomatsakis opened this issue Oct 3, 2022 · 6 comments
Assignees
Labels
brainstorm Brainstorming how something might work question Further information is requested

Comments

@nikomatsakis
Copy link
Member

In the current dada syntax, if you use = you declare a new variable:

x = 22

and if you use :=, you can reassign an existing place:

x := 23
y.field := 23

I was going for an extremely "lightweight" syntax reminiscent of Python, but to be honest, I'm not sure I like it. I am thinking maybe it's better to follow Rust (and, I realize, Java/TypeScript?) precedent here and use let:

let x = 22

and then just use = for reassignment:

x = 23
y.field = 23

Thoughts?

@nikomatsakis nikomatsakis added question Further information is requested brainstorm Brainstorming how something might work labels Oct 3, 2022
@nikomatsakis
Copy link
Member Author

This probably makes parsing easier too, as you would presumably write

let x: Type

and

let atomic x

Right now we need a bit of goofy lookahead to handle these cases.

@vemoo
Copy link
Contributor

vemoo commented Oct 3, 2022

I prefer having let, it's easier to see where new bindings are being introduced.

@nikomatsakis
Copy link
Member Author

@vemoo want to try implementing it?

@vemoo
Copy link
Contributor

vemoo commented Oct 5, 2022

sure

@vemoo vemoo self-assigned this Oct 5, 2022
bors bot added a commit that referenced this issue Oct 13, 2022
221: Let declarations r=nikomatsakis a=vemoo

Implements #217

I was going to update the book but I think it was already outdated since it uses `my foo = bar` instead of `foo: my = bar`. ¿Should updating the book be a separate PR?.

Also I didn't find any test for atomic local variable declarations, ¿should one be added?

Co-authored-by: Bernardo Uriarte <[email protected]>
@brson
Copy link
Contributor

brson commented Nov 27, 2022

I also prefer keywords to introduce variables. I think it's because it's a strong visual indicator that new state is being created.

@vemoo
Copy link
Contributor

vemoo commented Nov 30, 2022

this was implemented in #221

@vemoo vemoo closed this as completed Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brainstorm Brainstorming how something might work question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants