This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
For example, can I implement a Vector(n) to represent a mathematical n-dim vector?
var Vector(dim: u32) = struct {
.data: [dim]f64
}
fn wedgeProduct(vec1: Vector(m), vec2: Vector(k)) Vector(m*k) {
//... Implementation that references m and k
}
In this Vector type, .dim
is runtime-known and constant (i.e. Vectors don't change size)
I know I can return struct definitions from functions, but that doesn't allow me to write a function with a signature like wedgeProduct
, or I haven't been able to figure out how.
Should I give up on the array notation, and have my structs hold a dim
field and a pointer to an appropriately-sized array? How would I enforce that the array size cannot change?
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Zig/comment...