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

Support binary integer literals using 0b, as in Java #10656

Merged
merged 1 commit into from Jan 11, 2024

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Jan 10, 2024

Support binary integer literals. For example:

scala> 0b00101010
val res0: Int = 42

This language change was approved by the SIP (Scala Improvement Process) committee: SIP 42, https://docs.scala-lang.org/sips/binary-integer-literals.html

revival of #8275

@scala-jenkins scala-jenkins added this to the 2.13.14 milestone Jan 10, 2024
@som-snytt som-snytt modified the milestones: 2.13.14, 2.13.13 Jan 10, 2024
@som-snytt som-snytt requested a review from lrytz January 10, 2024 01:52
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jan 10, 2024
spec/01-lexical-syntax.md Outdated Show resolved Hide resolved
[‘L’ | ‘l’]
decimalNumeral ::= digit {digit}
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit {hexDigit}
binaryNumeral ::= ‘0’ (‘b’ | ‘B’) binaryDigit {binaryDigit}
binaryDigit ::= ‘0’ | ‘1’

Choose a reason for hiding this comment

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

Suggested change
binaryDigit ::= ‘0’ | ‘1’

Since there is no reminder of hexDigit, there probably shouldn't be one for binaryDigit

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 noticed digit was removed (because it's a char class?); and hexDigit was promoted to earlier section because of unicode escape. But maybe the rule of thumb should be "this is obvious so defer to the summary" as opposed to "chapter summary should be complete".

Choose a reason for hiding this comment

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

I think that is a good rule of thumb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, I took both edits. The earlier hexdigit might be unnecessary, but the context is (TIL):

scala> val `\u0061\u0062\u0063` = 42
val abc: Int = 42

Choose a reason for hiding this comment

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

Yeah I learned that as well a couple days ago, it's a cool feature in case you are restricted to ASCII, but still need to access some unicode-named methods

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LGTM

@som-snytt
Copy link
Contributor Author

som-snytt commented Jan 11, 2024

I was too lazy to change the assert to existing check_success, and also too lazy to rename check_success to success ✔️ using unicode.

Also, I wanted to avoid merge commit for trivial one-commit PR, but I'm not actually sure what the github button does. On dotty, they complained about losing merged commit messages in the plural case. Maybe unallowed rebase button is what preserves your commit?

@som-snytt som-snytt merged commit e59b420 into scala:2.13.x Jan 11, 2024
3 checks passed
@som-snytt som-snytt deleted the sip/42 branch January 11, 2024 21:37
@som-snytt
Copy link
Contributor Author

So the text undefined in the UI is actually the text. How annoying! It should say, "This space intentionally left blank."

As it warns, the "author" was me; well, Foucault already told us that label is without stable meaning. Undoubtedly, I don't have a display name configured.

Having the PR number in the comment header is handy; usually one must click thru to the commit to find where github displays the associated PR.

Dotty must be using rebase and merge.

commit e59b420e8a7aed7e63de316a88be42f291bc3aac (HEAD -> test/current, upstream/2.13.x)
Author: som-snytt <som.snytt@gmail.com>
Date:   Thu Jan 11 13:37:44 2024 -0800

    SIP 42 Binary literals finds acceptance (#10656)

    undefined

@SethTisue

This comment was marked as resolved.

@SethTisue SethTisue changed the title SIP 42 Binary literals finds acceptance Support binary integer literals, with 0b, as in Java Feb 10, 2024
@SethTisue
Copy link
Member

FYI and thanks @NthPortal

@SethTisue SethTisue changed the title Support binary integer literals, with 0b, as in Java Support binary integer literals using 0b, as in Java Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
5 participants