Named parameters: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 2,094: | Line 2,094: | ||
whatever bar:=1, baz:=2, foo:=-1, qux:="Why is ev'rybody always pickin' on me?" |
whatever bar:=1, baz:=2, foo:=-1, qux:="Why is ev'rybody always pickin' on me?" |
||
End Sub</syntaxhighlight> |
End Sub</syntaxhighlight> |
||
=={{header|V (Vlang)}}== |
|||
1) Vlang allows for struct a literal to be passed to the function, instead of named parameters. |
|||
2) Using this style, fields need not appear in the same order as they are declared |
|||
3) If one or more are omitted, their default values will be used instead. |
|||
4) The named parameter feature was deliberately omitted, for greater code readability. |
|||
5) Depending on the situation, variadic and/or sum types can also be considered. |
|||
<syntaxhighlight lang="Zig"> |
|||
struct Params { |
|||
a int |
|||
b int |
|||
c int |
|||
} |
|||
fn a_fn(p Params) int { |
|||
return p.a + p.b + p.c |
|||
} |
|||
fn main() { |
|||
x := a_fn(Params{a: 1, b: 2, c: 3}) // same order |
|||
println("x = ${x}") |
|||
y := a_fn(Params{c: 3, b: 2, a: 1}) // different order |
|||
println("y = ${y}") |
|||
z := a_fn(Params{c: 2}) // only one field |
|||
println("z = ${z}") |
|||
} |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
x = 6 |
|||
y = 6 |
|||
z = 2 |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |