functional.cafe is one of the many independent Mastodon servers you can use to participate in the fediverse.
functional.cafe is an instance for people interested in functional programming and languages.

Server stats:

223
active users

#zig

20 posts13 participants1 post today
Public

THAT SAID. . .

I can't get #Zig's document generator to generate stuff for all of my zig files. Which, I guess, is fine, I know it's in preview, technically, but. . .ugh. It's SO CLOSE TO AWESOME.

Public

Holy crap, #Zig documentation comments are awesome, too.

One of my favorite parts of the #DotNet ecosystem is the documentation system, where you get XMLdocs for free, and they have a first party tool for generating a docs web site.

For a while, though, I've been lamenting that weird HTML-based DSL from dotnet.

Not only do I not need to use another tool for Zig docs, I get to use MARKDOWN, like the gods intended.

Public

Ooooooooooooh.

#Zig files are, themselves, structs.

This is awesome, and explains some of my confusion around namespacing and stuff.

Also: custom formatters for structs? So nice. Love the member accessing syntax.

Hot damn I haven't been this excited about a language in a few years.

Public

Okay, Ziguanas, is this really the best we can do for "interfaces" in #Zig?

I can't think of another way to do it.

```zig
// The interface
pub const BusDevice = struct {
ptr: *anyopaque,
min_address: u16,
max_address: u16,
readFn: *const fn (ptr: *anyopaque, addr: u16) u8,
writeFn: *const fn (ptr: *anyopaque, addr: u16, value: u8) void,

fn read(self: BusDevice, addr: u16) u8 {
return self.readFn(self.ptr, addr);
}
fn write(self: BusDevice, addr: u16, value: u8) void {
self.writeFn(self.ptr, addr, value);
}
};

// The implementation
pub const Memory = struct {
min_address: u16,
max_address: u16,
physical_memory: []u8,

pub fn new(allocator: Allocator, min_address: u16, max_address: u16) !Memory {
const phys_mem = try allocator.alloc(u8, max_address - min_address);

for (phys_mem) |*address| {
address.* = 0;
}

return Memory{
.min_address = min_address,
.max_address = max_address,
.physical_memory = phys_mem,
};
}

pub fn write(self: *Memory, address: u16, value: u8) void {
self.physical_memory[address] = value;
}

pub fn read(self: *Memory, address: u16) u8 {
return self.physical_memory[address - self.min_address];
}

pub fn busDevice(self: *Memory) BusDevice {
return BusDevice{ .ptr = self, .min_address = self.min_address, .max_address = self.max_address, .readFn = self.read, .writeFn = self.write };
}
};
```

Public

Okay, so, tonight's stream is going to be one of two things:

Me doing codeberg.org/ziglings/exercise

Or Me starting the porting of my 6502 #emulator to #Zig

I'm going to start with the latter, but if I run into any roadblocks I'm going to default to the former.

This will be a temporary thing, I'm just a little burned out on my C# projects right now and need something fresh.

If you'd like to support my shameless pursuance of useless programming language knowledge, head on over to twitch.tv/b4ux1t3 tonight at roughly 8:30 PM Eastern!

#LiveCoding

. . .

That's the end of the post, really. Just want to push the next bit below the fold.

. . .

On a more personal note, the proceeds from my channel are currently being put toward buying a new water heater. So, like, if you wanna help someone out for free, feel free to hop on the stream and leave it running in the background while you do much more important things like, I dunno, sleeping ;)

Additionally, I do have a neglected ko-fi account that I need to revamp: ko-fi.com/b4ux1t3

Generally the ko-fi is supposed to be for my kids' education, but we're making an exception since "hot water" is kind of important.

Thanks for reading below the fold. You are beautiful and worthy, and I hope you have a wonderful day.

Summary card of repository ziglings/exercises
Codeberg.orgexercisesLearn the ⚡Zig programming language by fixing tiny broken programs.
Public

#Zig is the language teenage me would have written if teenage me had been any good at writing languages.

It literally addresses all of the problems I had with C.

Well, so far.

Public

So. . .if I print a pointer for an array in #Zig, I can see the whole array. If I print an individual value, I see the address (And datatype, which is cool).

Do arrays work significantly differently in zig from C? Like, i the pointer to the array the same as the pointer to the value, but the compiler is injecting some magic into the format string?

Public

I'm gonna try a thing:

I've been letting a few projects languish for a while now. One of them is my 6502 emulator, which I ported from c++ to #CSharp a few years ago.

I kind of want to port it again, or maybe just reimplement it.

The top of my list is a real grab bag of languages:

#Rust
#Zig
#Swift
#GoLang

I may just get some of the basic addressing logic done in each of them and see what sticks.

They're in rough order of "what I want to play with", though of all of them I have the most familiarity with rust. With Zig I have practically zero experience, and the other two sit somewhere in between.

The point here is not to start language wars, and I'll straight up mute anyone who tries, but I'd love to hear folks' thoughts.

If you want to make the case for another language, feel free to drop them in the replies! Really only looking for statically-compiled languages, and I'm not writing it in Java. ;)

Edit: Oh, and, boosts appreciated!