Skip to content

Is is possible possible to use the default attribute in fn in mojo? #826

Closed Locked Answered by rarebreed
tic-top asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Small independent features

There are a number of features that are missing that are important to round out the language fully, but which don’t depend strongly on other features. These include things like:

  • Keyword arguments in functions: foo(x=42)

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 = 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tic-top
Comment options

Answer selected by tic-top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants