Implement more conversions for primitive types #174
Labels
feature-request
Any request for a new feature of the language. Includes both syntax and library features.
good first issue
An issue that provides a good intro to working with the Myst codebase. Be helpful!
nativelib
Any issue relating to the native library (Crystal code) of Myst.
Milestone
Recently I needed to convert an Integer to a Float for a calculation to work properly, but I realized there's no method to do this directly. Instead, I had to do
1.0 * iterations
to convert the value.Having conversion methods between primitive types would make this much more clear and is generally expected by most people coming from Ruby or Crystal.
Conversions I think need implementing (not necessarily complete):
Integer#to_f
Float#to_i
(should truncate the value, not round)Float#round
(should round to the nearest Integer value, e.g.0.5
would round to1
)String#to_i
(see Crystal's API)String#to_f
(see Crystal's API)For an example of how these methods can be implemented as "passthroughs", see examples like
Float#to_s
, which just calls Crystal'sto_s
on the receiving value:myst/src/myst/interpreter/native_lib/float.cr
Lines 50 to 52 in 3ec71d3
The text was updated successfully, but these errors were encountered: