Mojo module
defines
Implements functions for retrieving compile-time defines.
You can use these functions to set parameter values or runtime constants based on name-value pairs defined on the command line. For example:
from std.sys import is_defined
comptime float_type = DType.float32 if is_defined["FLOAT32"]() else DType.float64
# Use `float_type` as a constant.And on the command line:
mojo -D FLOAT32 main.mojoFor more information, see the Mojo build docs.
The mojo run command also supports the -D option.
You can import these APIs from the sys package. For example:
from std.sys import is_definedcomptime values
MOJO_VERSION
comptime MOJO_VERSION = MojoVersion()
The version of the Mojo language used for the current compilation, available at compile time.
Structs
-
MojoVersion: Represents the Mojo version as major, minor, and patch numbers.
Functions
-
get_defined_bool: Get a boolean-valued define. If the name is not defined, return a default value instead. If the name is defined this will returnTrueif the value is ("1", "true", "True", "TRUE", "on", "On", "ON") otherwise it will returnFalse. -
get_defined_dtype: Try to get a DType-valued define. If the name is not defined, return a default value instead. -
get_defined_int: Try to get an integer-valued define. Compilation fails if the name is not defined. -
get_defined_string: Try to get a string-valued define. Compilation fails if the name is not defined. -
is_defined: Return true if the named value is defined.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!