-
-
Notifications
You must be signed in to change notification settings - Fork 154
Syntax Changes #503
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 Changes #503
Conversation
As always thanks for your work. Looking forward to arriving at 1.0.0 in the future. Is this going to be deprecated first? I like the potential for less verbose code, but I do like the explicit nature of try, sequence, and parallel. How would the following be rewritten to conform with the changes above?
|
@morpatr Thanks for the feedback! This is what that code look like:
|
Overall a fan! As much as I also like the explicitness (and cool factor) of I like the change to Is there an example of how you do something like |
@jansul I'm still trying to figure out how can Let's say we have two requests to make, previously it would look like this:
Now it could just be this:
The compiler has all the information to decide to do It's not implemented yet though. |
I played around with migrating mint-realworld to use this branch - mostly to get a feel for the new syntax. Overall was fairly painless - and as pleasant to use as mint always is 🥰 There were a couple of places where
One bug I did notice was that if you had a trailing assignment, something like this:
It would generate JS similar too this (with a
I removed |
e7c1e21
to
72ec4bf
Compare
554ff5b
to
ab9931d
Compare
I think this could be a problem. For example, I'm a javascript developer and I understand how async/await works on JS, so I could do:
Suppose that is the first Anyway, I am a super noob with mint, so my opinions could be erroneous |
After thinking about it some, I came to the same conclusion. I might reintroduce the |
I still thinking sequence/parallel are two great tools and shouldn't remove. Sorry to bother you. It's a big language and I hope it grow |
ab9931d
to
0b20457
Compare
0d69bff
to
149292b
Compare
69c3c27
to
b4f5d5d
Compare
This PR is kind of ready, here are the final list of changes:
|
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.
Looks awesome! 🤩
Can't wait to see the new wave of fresh 🌿 !
Couple of suggestions:
- Revert "The name of the enum is now optional and the variant can be used alone as a reference." since it will most likely cause problems in the future
- Reverse the
:
and=
usage, so the records will be defined with:
({ foo: "bar" }
) - Switch the order of arguments, so the pipe receiver will always comes first
- Records now use `:` instead of `=` - Statements now use `let` and `=` instead of `:`
These were implemented in this PR, should be ready for merging 🚀
This is a separate PR #571 |
@@ -200,12 +185,11 @@ module File { | |||
input.multiple = true | |||
input.type = 'file' | |||
|
|||
document.body.appendChild(input) |
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.
@gdotdesign Was that removed intentionally?
I'm asking since there's still document.body.removeChild(input)
left beneath 🤔
This PR implements a syntax changes that I wanted to do before 1.0.0. These changes hopefully will make the language more understandable and more welcoming to newcomers.
The main change stems from the issue of allowing only one expression per code block (function body, if / else branches, case branches, etc...) #394, also I wanted to simplify the language a bit.
Code Blocks
This PR makes it possible to write multiple statements in a code block without a
try
like this:Code blocks can also be used by themselves as an expression:
I hope this will make code less verbose and reduce overall boilerplate.
Await and Promises
Previously, the way to handle promises was through using
sequence
orparallel
. From the feedback over the years, I found that it's hard for people to understand how they work, so this PR removes those constructs and adds anawait
keyword which can be placed before a statement:There are two rules to keep in mind when working with
await
:await
keyword awaits the givenPromise(a)
and returns its valuea
Promise
(since it's asynchronous).Other things:
await
can be used without a variable:the
Promise
type changed fromPromise(error, value)
to justPromise(value)
Removed language features
where
- since we can add statements directly before the expression this is removedwith
- it was not used and not documentedtry
- was replaced by code blockssequence
- was replaced by code blocks and awaitparallel
- was not used widely, and it's partially replaced with code blocks and awaitcatch
,finally
,then
- these were constructs used intry
,sequence
andparallel
Standard library update
The standard library https://github.com/mint-lang/mint/tree/code-blocks/core was updated as well and all tests are passing. You can check how these changes looks as well.
Call for comments and questions
I would like to have feedback to these changes, so I ask you to share your feelings / questions about this in the comments 🙏