V: default arguments for function

Created on 13 Dec 2019  ·  3Comments  ·  Source: vlang/v

That will be exciting if a function has default arguments.
such as:

fn foo(bar string, count int =1) {
    for _ in [..count] {
        print(bar)
    }
}

foo('hello') // -> hello
foo('hello', 3) // -> hellohellohello

Thankyou!

Feature Request

Most helpful comment

V will have no function overloading/default arguments, but it will have
foo({bar:1})

where foo is fn foo(args struct {bar int, baz int = 10})

so baz is set to 10 by default

All 3 comments

I'm new here, but this might go against the Safety Values

https://vlang.io/

Safety
No null
No global variables
No undefined values
No undefined behavior
No variable shadowing
Bounds checking
Option/Result types
Generics
Immutable variables by default
Pure functions by default
Immutable structs by default


Having said this. I love and miss this feature from python. I would accept it in any language :+1:

V will have no function overloading/default arguments, but it will have
foo({bar:1})

where foo is fn foo(args struct {bar int, baz int = 10})

so baz is set to 10 by default

ok, got it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lobotony picture lobotony  ·  3Comments

penguindark picture penguindark  ·  3Comments

elimisteve picture elimisteve  ·  3Comments

clpo13 picture clpo13  ·  3Comments

medvednikov picture medvednikov  ·  3Comments