-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow variadic functions with variable types #21462
Comments
If it is decided that V should not allow defining V functions with variable variadic types for strong typing reasons, it is understandable. But V should at least allow declaring external C functions as such, otherwise how would I declare an external C function defined as such: void hello(int i, double f, ...) where the call could be hello(1, 2.3, a_struct) or hello(1, 2.3, "peter", 4) or hello(1, 2.3, 4, 5.6, 7) ? |
You can circumvent this by stating that the argument is a struct struct Args {
x int = 0
y f32 = 0.0
p &Person = unsafe { nil }
d f32 = 0.0
}
fn Hello(args Args) {
println(args.x)
}
fn main() {
Hello(x: 1.0)
Hello(x: 1.0, y: 0.0, p: &Person{}, d: 3.1415)
} With this you can define the behaviour of how the function should act with different values. |
You could also create a sum type. You can do variadic sum types. |
Yep something like this would work type Arg = f32 | int | Person | string
fn Hello(arg1 Arg, arg2 Arg, arg3 Arg, arg4 Arg) {} |
Or, to match the request... type Arg = f32 | int | Person | string
fn Hello(args ...Arg) {} |
Describe the feature
Allow defining V fn hello(i int, f f64, ...) or declaring external C functions as such.
Use Case
At the moment it seems V does not support defining/declaring a function where the variadic part has variable types, like what C and some other programming languages allow.
Instead of defininng/declaring a series of functions:
fn hello(i int, f f64, x int, y string)
fn hello(i int, f f64, y string)
fn hello(i int, f f64, p &Peter)
...and so on...
I'd like to only define/declare a single function:
fn hello(i int, f f64, ...)
Proposed Solution
As mentioned, allow defining V functions like fn hello(i int, f f64, ...) and declaring external (eg. C) functions as such.
Other Information
No response
Acknowledgements
Version used
V 0.4.5
Environment details (OS name and version, etc.)
Mac OS X, 10.15.7
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: