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

Fix example that did not compile and following paragraph #18065

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

Sporarum
Copy link
Contributor

@Sporarum Sporarum commented Jun 26, 2023

Compiling the code on latest main gives:

{
  val x = f(x: Int, y => // Recursive value x needs type
    x * (
      y + 1
    ) +
    (x +
    x)
  )
}

Which makes sense as we basically write val x = f(x)

@Sporarum Sporarum changed the title Fix example that did not compile, and following paragraph Fix example that did not compile and following paragraph Jun 26, 2023
@Sporarum Sporarum requested a review from bishabosha June 26, 2023 14:21
@bishabosha
Copy link
Member

does this have an issue that should be linked?

@@ -261,7 +261,8 @@ Indentation can be mixed freely with braces `{...}`, as well as brackets `[...]`
For instance, consider:
```scala
{
val x = f(x: Int, y =>
val x = 4
f(x: Int, y =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a neophyte, I can't tell if : Int is intended.

It would be poetic justice to val x = 3. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works because for example val y = x: Int is valid, it widens the type of the expression to Int

And since you can use arbitrary expressions as parameters, val y = f(x: Int) is valid

Copy link
Contributor

@som-snytt som-snytt Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrasing: as a neophyte, : Int is confusing to me. What is it an example of? What does it illustrate? There is no definition of f, is that correct? Therefore, it is not a cut/paste example. Of course, the language reference is permitted to be arbitrarily obscure.

Edit: I should have added, I have no inner need to be right here or to be heard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was some way to illustrate that the parser isn't treating the argument list like 2 lambda parameters? but its strange to use it there. It probably shouldn't be there unless it specifically illustrates something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I 100% agree, I didn't change it because I wanted this PR to be minimal

I did not look at other parts of this page than the examples either, there might be other improvements possible

@Sporarum
Copy link
Contributor Author

does this have an issue that should be linked?

Sorry I updated the post to give a bit more context, I discovered this while making #18066

@bishabosha bishabosha merged commit 294b5da into language-reference-stable Jun 27, 2023
34 checks passed
@bishabosha bishabosha deleted the Sporarum-patch-1 branch June 27, 2023 08:27
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.

3 participants