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

Default function argument values #29

Closed
kengorab opened this issue Jul 14, 2019 · 0 comments
Closed

Default function argument values #29

kengorab opened this issue Jul 14, 2019 · 0 comments

Comments

@kengorab
Copy link
Owner

kengorab commented Jul 14, 2019

Related to #23, this is the ability for functions to have default parameter values

func myAdd(a: Int, b: Int, c: Int = 0) = a + b + c

func myAdd2(a: Int, b: Int, c = 0) {
  val sum = a + b + c
  sum
}

Implementation notes:

Let's say we have this function:

func abc(a: Int, b = 1, c = "hello"): String = a + b + c

Behind the scenes, the following code will be generated:

func abc_$1(a: Int) = abc(a, 1, "hello")
func abc_$2(a: Int, b: Int) = abc(a, b, "hello")

(the _$2 means "the version of the abc function, with arity 2). Those 2 parameters would be forwarded to the underlying function, with the 3rd param receiving its default value of "hello".

This means that the logic for invocation also needs to be aware of these "pesudo-functions"

@kengorab kengorab created this issue from a note in Language Core (To Do) Jul 14, 2019
@kengorab kengorab moved this from To Do to In Progress in Language Core Aug 3, 2019
@kengorab kengorab moved this from In Progress to To Do in Language Core Aug 3, 2019
@kengorab kengorab moved this from To Do to In Progress in Language Core Sep 1, 2019
@kengorab kengorab closed this as completed Sep 2, 2019
@kengorab kengorab moved this from In Progress to Done in Language Core Sep 2, 2019
@kengorab kengorab moved this from Done to New Done in Language Core May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant