-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
feat!: Char #474
feat!: Char #474
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.
Just a couple questions
let succ = (c) => { | ||
let codePoint = code(c) | ||
if (codePoint == max) { | ||
fail 'no valid Unicode code point past U+10FFF' | ||
} else if (codePoint == 0xD7FF) { | ||
fromCode(0xE000) | ||
} else { | ||
fromCode(codePoint + 1) | ||
} | ||
} |
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.
Thoughts on succ
and pred
returning Options?
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.
Since these only fail in one pretty specific (and uncommon) case, it didn't really seem necessary to me. Feels like the kind of thing you would always just Option.get
without doing any checking.
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.
Alright, let's make sure to document it and give the reasoning somewhere. I think that's especially important for contributor docs.
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, for sure.
export function fromCode(code: u32): u32 { | ||
code = code >>> 1 | ||
if (code < 0x80) { | ||
let char = allocateChar() |
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.
Any reason for having this twice instead of once at the top?
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.
Not really. This way feels a tad more clear to me since all of the code for the "fast" case is contained within the if
. We'd get a few bytes back if we moved it up though.
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.
Seems fine. Was just curious.
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.
Reasoning seem good to me! 👍
Char
This PR adds the
Char
type to Grain. Like other hip modern languages, a GrainChar
is a single Unicode scalar value instead of a single byte. 😎 (For single bytes, we'll probably introduce aByte
type.)The Char Stdlib
This PR also includes some char utilities in a new Char stdlib.
Breaking Changes
This PR is a breaking change because
String.explode
was updated to return an array of characters instead of strings.Character Literal Syntax
There is currently no syntax to create character literals, as we have yet to decide on a syntax.