-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
first pass at cheatsheet for scala #348
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you! Terribly sorry for the delay, my inbox overwhelmed me
cheatsheets/gleam-for-scala-users.md
Outdated
/** | ||
* a very special trait. | ||
*/ | ||
trait Foo {} |
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.
Could you remove the foobar references please.
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.
yea I think these just came from using php as a starting point; will remove them
cheatsheets/gleam-for-scala-users.md
Outdated
size2 = 1 | ||
``` | ||
|
||
Scala uses `val` for immutable bindings and `var` for mutable bindings. |
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.
Let's remove explanations and examples of var
and the scoping rule below, as we don't need to teach Scala and there's no equivalent in Gleam.
cheatsheets/gleam-for-scala-users.md
Outdated
In Gleam, `let` and `=` can be used for pattern matching, but you'll get | ||
compile errors if there's a type mismatch, and a runtime error if there's | ||
a value mismatch. For assertions, the equivalent `let assert` keyword is | ||
preferred. |
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.
let assert
is required, not preferred. let
does not result in a runtime error as it does not permit value mismatches
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'll take a pass at re-writing this, but it's also included in the Elm, Elixir and several other pages, so you might want to update those too.
cheatsheets/gleam-for-scala-users.md
Outdated
For methods with no arguments, you may omit the parenthesis | ||
|
||
```scala | ||
|
||
def noArgs = "Surprise." | ||
|
||
``` | ||
|
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.
For methods with no arguments, you may omit the parenthesis | |
```scala | |
def noArgs = "Surprise." | |
``` |
We don't need to teach Scala
cheatsheets/gleam-for-scala-users.md
Outdated
```scala | ||
def main() = { | ||
val x = { | ||
someFunction(1) | ||
2 | ||
} | ||
// Parenthesis are used to change precedence of arithmetic operators | ||
// Although curly braces would work here too. | ||
val y = x * (x + 10) | ||
y | ||
} | ||
``` | ||
|
||
or using indentation in Scala 3 | ||
|
||
```scala | ||
def main() = | ||
val x = | ||
someFunction(1) | ||
2 | ||
val y = x * (x + 10) | ||
y | ||
``` |
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.
```scala | |
def main() = { | |
val x = { | |
someFunction(1) | |
2 | |
} | |
// Parenthesis are used to change precedence of arithmetic operators | |
// Although curly braces would work here too. | |
val y = x * (x + 10) | |
y | |
} | |
``` | |
or using indentation in Scala 3 | |
```scala | |
def main() = | |
val x = | |
someFunction(1) | |
2 | |
val y = x * (x + 10) | |
y | |
``` | |
```scala | |
def main() = { | |
val x = { | |
someFunction(1) | |
2 | |
} | |
val y = x * (x + 10) | |
y | |
} |
Can drop some of the info on Scala
cheatsheets/gleam-for-scala-users.md
Outdated
} | ||
``` | ||
|
||
As all expressions the case expression will return the matched value. |
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.
What does this mean?
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.
yeah this is from PHP as well and I think the author just meant the case expressions are expressions so
let x = case y {
...
}
x
is getting assigned to the "matched value". But I'm going to remove this because "matched value" really sounds more like the input (i.e. y
) than the right hand side of the ->
Thanks for the thorough review! I'll try to get these edits done soon |
efe5861
to
e47ade1
Compare
Sorry that took me way longer than it should have. If I find some more time I can open a separate PR to backport some of these fixes to the Elixir/PHP/Elm pages. |
Hello,
For your consideration, I've written a cheatsheet for Scala programmers. I think by most measures Scala is the most mainstream fp language in industry and has a lot of similarity with Gleam. Both are highly influenced by ML family of languages but use a more C-style syntax.
I'm not sure how you decide which languages deserve a dedicated cheatsheet, and I realize this is more (basically untestable) code that needs to be maintained. So I will be understanding if you're not accepting these types of contributions.
There's also probably some mistakes, I based this off of the PHP cheatsheet but read several others to get ideas for what else to cover. I tried to keep in mind the audience should be Scala programmers looking into Gleam and not as much the other direction, so there's tons of omissions about Scala's huge type system.
Additionally, I think it would make sense to draw a comparison between the
use
expressions and Scala'sfor
comprehensions, but I didn't see an obvious spot for that. Another minor thing to add is thetodo
vs Scala's???
(which seems to have inspiredtodo
) but that seems less important for real-world code.