-
Is is possible possible to use the default attribute in fn in mojo? |
Beta Was this translation helpful? Give feedback.
Answered by
rarebreed
Sep 17, 2023
Replies: 1 comment 1 reply
-
Default attribute? You mean a keyword argument with a default value in a function like this? fn defaulted_fun(age: Int = 20) -> Int:
return age * 2 or def defaulted_def(age = 20):
return age * 2 if that is what you mean, then no. Keyword arguments with default values are not supported in mojo yet.
This also applies on the calling side. You can't do this either fn regular_fn(age: Int) -> Int:
return age
fn main():
let doubled = regular_fn(age = 20) # error here, since keyword args not supported. uncomment the lines below
# need to call it without keyword arg
# let doubled = regular_fn(20) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tic-top
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Default attribute? You mean a keyword argument with a default value in a function like this?
or
if that is what you mean, then no. Keyword arguments with default values are not supported in mojo yet.
This also applies on the calling side. You can't do this either