#Help With Tuples
1 messages · Page 1 of 1 (latest)
var result: struct { u32, ?*anyopaque } = .{ 0, null } not giving it a type makes it a bit less useful
Interesting
iirc itll be a struct { comptime_int, @TypeOf(null) } as you had it, theres no default int type and it cant infer what kind of “nullable” you want
Can you name the individual values? I know that's basically a struct at that point but I'm trying to just do multiple return without needing to declare a struct
Fixed my issue btw :)
yeah, you can name them, but structs dont have structural equality like tuples do. and you cant destruct them
so youd have to declare a struct. or just make result the two items seperately and do return .{ .a = result_a, b = result_b }
or to be silly you could inspect the return type of the current function lol
Wait what. Wdym structural equality. Also I do just want to return a tuple because I don't want to use a struct
Also that's kind of ironic that structs don't have structural equality
structural equality pretty much means that two types that have the same structure are considered the same type. like struct { T } == struct { T } works but struct { name: T } == struct { name: T } doesnt.
probably because structs with named fields dont have a defined layout while i think tuples do? and tuples cant have member functions
although extern structs also have a defined layout so maybe its more about explicit coercion between genuinely “different” types
oh if your question was if you could name specifically tuple fields, no. they’re always “unnamed” (though each field does have a name, its just the index you access it at, so you can do tuple_val.@"0" if you wanted to)
Oh since you mentioned it, what's the difference between extern and export?
extern on a struct means “conform this struct to the C ABI”. export is kinda the same thing for functions, i dont know the terms but its for making a library that C can call into
well, C and anything that can call into C. like cross-language stuff
Or you can destructure tuples and give it better name like const x, const y = theTuple