Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to add conditional parameters to functions #13

Open
eliassjogreen opened this issue Mar 19, 2022 · 0 comments
Open

Proposal to add conditional parameters to functions #13

eliassjogreen opened this issue Mar 19, 2022 · 0 comments
Labels
proposal A proposal to add a new feature to the language

Comments

@eliassjogreen
Copy link
Member

eliassjogreen commented Mar 19, 2022

Conditional parameters, while only syntax sugar would be a cool way of doing different things when the input of the function is different. I am undecided on wheter this is a good idea as it is just syntax sugur and would complicate things like compilation and type checking but its a cool idea at least:

// recursively calculate the factorial of n
fn fac(n: u64): u64 {
  return n * fac(n - 1)
}

// when parameter n is 1 call this function instead
fn fac(n: u64 == 1): u64 {
  return 1
}

The above code would be equivalent to, and while not in this case shorter it is in some ways more readable (and in some ways not):

fn fac(n: u64): u64 {
  if n == 1 {
    return 1
  }

  return n * fac(n - 1)
}
@eliassjogreen eliassjogreen added the proposal A proposal to add a new feature to the language label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal A proposal to add a new feature to the language
Projects
No open projects
Development

No branches or pull requests

1 participant