Mojo function
env_get_int
env_get_int[name: StringLiteral]() -> Int
Try to get an integer-valued define. Compilation fails if the name is not defined.
Parameters:
- name (
StringLiteral
): The name of the define.
Returns:
An integer parameter value.
env_get_int[name: StringLiteral, default: Int]() -> Int
Try to get an integer-valued define. If the name is not defined, return a default value instead.
Example:
from sys.param_env import env_get_int
def main():
alias number = env_get_int[
"favorite_number",
1 # Default value
]()
parametrized[number]()
fn parametrized[num: Int]():
print(num)
from sys.param_env import env_get_int
def main():
alias number = env_get_int[
"favorite_number",
1 # Default value
]()
parametrized[number]()
fn parametrized[num: Int]():
print(num)
If the program is app.mojo
:
mojo run -D favorite_number=2 app.mojo
mojo run -D app.mojo
Note: useful for parameterizing SIMD vector sizes.
Parameters:
- name (
StringLiteral
): The name of the define. - default (
Int
): The default value to use.
Returns:
An integer parameter value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!