Is there any way to instantiate a tuple where one of the values is void? For example:
proc foo(tup: (string, void)) =
discard
foo(("foo", nil))
Nil is not void
Yup -- I'm aware nil is not void. The example I provided does not compile. But it's the closest I could think of to provide a void value.
Are you trying for default or optional parameters?
I'm working with codegen via macros. I'm trying to handle a situation where a user provided type is void.
pointer is the equivalent of void* of C
Do you have an example of how I would use this in practice?
Yes -- this all makes sense, but it doesn't help with my original question. If I've got a function signature like this, is it callable in any way?
proc foo(tup: (string, void))
Using nil was obviously contrived, but this also doesn't work:
foo(("bar", ))
If the answer is that it isn't possible -- that's totally reasonable. But I want to make sure that what I'm asking is not about type theory, it's about practical application.
As far as I know, void can only be used as a return type of a routine and is the return type in some situations as in the following example:
import std/macros
macro t(x: typed) =
echo repr x.gettype
func x() = discard
t(x)
It's an edge case of some macros I'm working on where the user could provide a void type -- I'm trying to determine if it is supportable. This works:
proc foo(tup: void) =
discard
foo()
So I was trying to see if there was an equivalent for tuples
This could be handled by something like the empty tuple ()?
The core threads API just specializes when you have "void" user argument type.
Though perhaps you could reuse std/macros unpackVargargs that handles applying void and non-void arguments.
assert void is type(void) #true
assert type(void) is void #true
assert void is void #true
assert nil is not void #true
assert void is not void #false
assert void is typedesc #true