This is a list of UNRELEASED changes for the Mojo language and tools.
When we cut a release, these notes move to changelog-released.md
and that's
what we publish.
[//]: # Here's the template to use when starting a new batch of notes: [//]: ## UNRELEASED [//]: ### ⭐️ New [//]: ### 🦋 Changed [//]: ### ❌ Removed [//]: ### 🛠️ Fixed
-
int()
can now take a string and a specified base to parse an integer from a string:int("ff", 16)
returns255
. Additionally, if a base of zero is specified, the string will be parsed as if it was an integer literal, with the base determined by whether the string contains the prefix"0x"
,"0o"
, or"0b"
. (PR #2273 by @artemiogr97, fixes #2274) -
Mojo now allows types to opt in to use the
abs()
function by implementing the__abs__()
method, defined by the newAbsable
:from math import sqrt struct Point(Absable): var x: Float64 var y: Float64 fn __abs__(self) -> Self: return sqrt(self.x * self.x + self.y * self.y)
-
The
abs()
function has also moved frommath
tobuiltin
, so you no longer need to dofrom math import abs
. -
Mojo now allows types to opt in to use the
floor()
andceil()
functions in themath
module by implementing the__floor__()
and__ceil__()
methods (and so conforming to the newmath.Floorable
andmath.Ceilable
traits, respectively). For example:from math import Ceilable, Floorable, ceil, floor @value struct Complex(Ceilable, Floorable): var re: Float64 var im: Float64 fn __ceil__(self) -> Self: return Self(ceil(re), ceil(im)) fn __floor__(self) -> Self: return Self(floor(re), floor(im))
- The method
object.print()
has been removed. Since now,object
has theStringable
trait, you can useprint(my_object)
instead.