I'm getting some weird errors, while following an example from Zig Programming Mastery book

I’m getting some weird errors, while following an example from Zig Programming Mastery book.

const std = @import("std");

const isPrime = comptime fn(n: u32) bool {
    if(n < 2) {
        return false;
    }

    for(var i:u32 = 2; i * i <= n; i += 1) {
        if(n % i == 0) return false;
    }
    return true;
}

pub fn main() !void {
    //
}

I’m not seeing what I’m doing wrong. The example is about comptime.

v0.13

from Zig Programming Mastery book

Never heard of this book.

That for loop is not Zig syntax, so I’m inclined to guess it’s something hallucinated by an LLM?

5 Likes

Yep, Definitely written by an AI

5 Likes

Ask for a refund :slight_smile:

While we’re on the topic: Zig does have a for loop, but it’s a kind of “ranged for”:

for (collection) |item| {
  // do something with item
}

Your use case needs a while loop.

var i: u32 = 2;
while (i * i <= n) : (i += 1) {
  // ...
}
2 Likes

Unfortunate. In the meantime, there is a “real” zig book which you can read for free online!

7 Likes

Highly recommend that book btw, I bought it to support the initiative, and didn’t thought I would learn much, but the book is really enjoyable, it’s straight to the point with just the right amount of explanation, and there is everything to really understand the language well, even just as a quick reference it’s really cool, I hope he makes another one in a few years.

Already have that book. Ty.

Thanks for the replies.

Maybe is an AI book. Maybe thats the big difference… its been over 10 years since I’ve manage to read non-stop pages after pages on a pdf/ebook about programming book without getting annoyed or frustrated. 99% of books make me stop reading after 2 sentences.

Its a book that is straight to the point… and teaches without bul** in the middle.
AI = 1, Humans = 0

I would never ask for a refund on a book that actually makes me read and do stuff.

I would prefer to get a refund on almost all the ones I got over the last 10 years.

If it has a mistake our several… most of them have… even on second and third editions.

ChatGPT, is that you? :face_with_raised_eyebrow:

10 Likes

So, AI wins by having a book that is easier to read and more enjoyable… and also full of incorrect content and hallucinations? That is one weird assessment.

11 Likes

AI often mix C code when you want something in Zig. Not usable (yet).

1 Like

From my perspective the most reasonable explanation for this whole thread is that OP is just using this thread to get more sales to the AI slop book in question.

I find that much easier to believe than somebody not only being ok with a programming manual not having even remotely correct syntax, but even praising it as page turner.

I’ve also seen the preview on Amazon… it’s unreadable.

Related link on pre-LLM book scams on Amazon that some might find interesting https://www.youtube.com/watch?v=biYciU1uiUw

Here’s an actual book recommendation that isn’t AI slop: GitHub - pedropark99/zig-book: An open, technical and introductory book for the Zig programming language

15 Likes

FWIW OP has a pretty fleshed out online presence, and has been a member on this site for quite some time, albeit not an incredibly regular one.

While I want to make it clear that I don’t believe that people should be required to have a massive online presence to be considered real, given that in this case we’re evaluating this as evidence against a very peculiar interaction that hints fairly strongly at a given conclusion, what I saw by clicking around OP’s socials not only does not disprove my suspicion, but actually makes me even more so.

I recommend looking at the contents of what’s on GitHub for example.

5 Likes

Indeed. Seems like something recently took over the socials. Back In 2023 the OP posted what looks like genuine contributions to threads on this site. Blog hasn’t been updated in a few years either. Strange.

C or Zig, I’m not sure about that. :face_with_raised_eyebrow:

Totally agree!

Sry, I dont known what OP means. I’m trying to learn Zig, and I found a book (the same way I found others), and started reading it because it look like it had simple examples since I wanted a simple introduction to zig. Found a problem half way through it and decide that this forum was the best place to ask for an anwser.

If the books was done by AI, or a real life person, not sure, dont care, my goal was to have a nice introduction that I could read to undertand some basic code.

I’ve done a couple of other things to learn Zig, like zigglings, but I wanted something diferent.

As a newbie I cannot tell if the book is good or not till someone tells me or after a bit of time understanding the language.
Yes I did enjoy the not crowded aproach of the book.

And also cannot disagree that half way through the book it starts getting weird with some non Zig code. But I only know till I get to that point and after learned a bit of the language.

NO, the whole thread is not to get sales, and I apologise if that was the conclusion.

I just wanted to know a simple anwserr to a simple question.

PS: If the book is damage for the Zig learning and if this is “boosting sales” … I can delete the thread… of someone higher above can.

OP = Original Post(er)

I recognize Pedro’s book in this screenshot, that’s legit, but are all these other ones LLM-generated books too?

It appears so… ooooof this is awful.

2 Likes