-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Extended number formatting #312
Conversation
f8ec0af
to
92504d2
Compare
19f3532
to
f5c5ea1
Compare
f5c5ea1
to
f281c35
Compare
book/src/procedures.md
Outdated
@@ -26,6 +26,15 @@ let speed = 25 km/h | |||
print("Speed of the bicycle: {speed} ({speed -> mph})") | |||
``` | |||
|
|||
Rust-style format specifiers are also supported in interpolations. For instance: |
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 not put too much emphasis on rust maybe?
Rust-style format specifiers are also supported in interpolations. For instance: | |
Format specifiers are also supported in interpolations. For instance: |
numbat/src/vm.rs
Outdated
strfmt::strfmt(&format!("{{value{}}}", specifiers), &vars) | ||
.map_err(|err| match err { | ||
strfmt::FmtError::Invalid(s) => { | ||
RuntimeError::InvalidFormatSpecifiers(s) | ||
} | ||
strfmt::FmtError::KeyError(_) => unreachable!(), | ||
strfmt::FmtError::TypeError(s) => { | ||
RuntimeError::InvalidTypeForFormatSpecifiers(s) | ||
} | ||
})?; |
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.
Can we please extract this into a function to avoid the duplication?
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.
The best I could do was extracting the function passed to map_err
. I couldn't get the strfmt::strfmt(...)
portion to be shared between the two branches because vars
has a different type in each branch (in one its values are of type f64
, in the other of type String
. I could maybe do some generic shenanigans or, god forbid, use a macro, but doesn't seem worth it to me.
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.
Very nice! Just a couple of minor suggestions.
f281c35
to
b3d995a
Compare
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!
Thanks! |
Changes are live on https://numbat.dev/ |
Fixes #264.
TODO:
strfmt