@matrix tfw rust code on your machine has been doing more SEGVs than code in C.
@pernia @matrix
const std = @import("std");

pub fn main() void {
const message: [3]u8 = "zug";
std.debug.print(message);
}
@pernia @matrix 'The Zig standard library is sort of object-oriented. Things are organized into structs with functions. They look a bit like methods, but are more like namespaces and syntax sugar.'

I guess.
@pernia @matrix i have no idea. The fuck is a 'struct with function'. Maybe like the functions only accept particular struct types as arguments but that's a retarded way to do it.
@MercurialBlack @matrix i imagined it was more like a C struct but they shoved in a function. maybe instead of being an object, its just a function that exists in the namespace of the struct, so that you can call the function by calling the namespace and then the name of the function, but internally its not an object.
@pernia @matrix @MercurialBlack Zig doesn't really have OOP-style inheritance, virtual dispatch, & shit, but you could probably hack that in with meta-programming if you REALLY wanted to (you can do that in C too, just with much more pain FWIW). The "structs with functions" just means you can do sneed.chuck() instead of Sneed_chuck(sneed) -- syntax sugar

pub is simply said just visibility for namespaces / modules / files / whatever tickles your shitbox (those are all structs in zig :akko_wink:)
@faggot @matrix @MercurialBlack would you hack all those features into a compiler, or into a library or what? i heard you can add shit into languages but i dont really undersatnd how that's done.
>"structs with functions" just means you can do sneed.chuck() instead of Sneed_chuck(sneed) -- syntax sugar
you mean like, sneed.chuck() will run chuck() with arguments "sneed"
@pernia @matrix @MercurialBlack

>would you hack all those features into a compiler, or into a library or what? i heard you can add shit into languages but i dont really undersatnd how that's done.

Zig has metaprogramming which lets you write functions that will run at compile time and can generate new structs and whatnot (Lisp had this in the 70s), only thing it can't do is make arbitrary new functions I think (Lisp could)

>you mean like, sneed.chuck() will run chuck() with arguments "sneed"

Yup, pretty much

const Sneed = struct {
...
pub fn chuck(self: Sneed) void { ... }
...
};
...
const sneed = Sneed{};
sneed.chuck(); // This calls the function chuck inside the Sneed struct/namespace and with sneed as its first argument
@faggot @matrix @MercurialBlack is "sneed" the first argument because the function is defined that way in the struct, or because you called chuck() but called it as sneed.chuck()
>Zig has metaprogramming which lets you write functions that will run at compile time and can generate new structs and whatnot
so like, you're adding functions that the compiler will run before compiling in order to change the way it compiles the code, into the sourcecode of your regular program, so that you can get those features you want without editing the compiler's source itself?
@pernia @matrix @MercurialBlack
>is "sneed" the first argument because the function is defined that way in the struct, or because you called chuck() but called it as sneed.chuck()

We're getting to levels I am not comfortable answering with my knowledge but I think it's because sneed is an instance of the struct (if I did Sneed.chuck then the struct acts like a namespace). And if the definition inside the struct wouldn't match it, I'd get a compile error. But maybe I'm wrong here

RE: metaprogramming

Yeah, somewhat like C's macros but it's all basically in the same language as "normal Zig" and can call other zig functions and yeah. But yes you don't have to edit the compiler to do it

fn Foo(comptime T: type) type {
return struct {
pub fn bar(x: T) T { ... }
};
}
var something: Foo(f64) ...

This is one example of how you can do generic types, the "function" Foo gets executed in compile time and it basically returns a new structure/namespace soo you can just use Foo(typename) as a type now.
You can also do all kinds of weirder stuff like procedurally create a new struct with @Type() builtin and whatnot but that'd be pretty ugly and I bet that API changes every release
@faggot @matrix @MercurialBlack
>We're getting to levels I am not comfortable answering with my knowledge but I think it's because sneed is an instance of the struct (if I did Sneed.chuck then the struct acts like a namespace). And if the definition inside the struct wouldn't match it, I'd get a compile error. But maybe I'm wrong here
so like normal OOP
>RE: metaprogramming
the FUCK IS THIS THISMAKES NO SENSE :screech:
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.