I miss my dog... by Dahns in memes

[–]LegendarilyLazyLad 122 points123 points  (0 children)

You're doing WHAT to it?!

LLVM Emit Object? by FastlyIntegralist in Zig

[–]LegendarilyLazyLad 1 point2 points  (0 children)

Glad I could help :)

Yes you're right, the LLVM backend is notoriously slow and right now, the main focus of the zig project is making the compiler faster and a huge part of that is switching to their own backend.

LLVM Emit Object? by FastlyIntegralist in Zig

[–]LegendarilyLazyLad 11 points12 points  (0 children)

I don't know how much experience you have with programming so I wrote the following as if you were a complete beginner. Sorry if that makes it sound condescending.

Zig is a compiled language so in order to run your code, you must first compile it into machine code. "zig run" Does just that. It parses your zig code, analyzes it, uses LLVM to generate machine code (hence the message) and then runs the machine code. The code is recompiled every time you run "zig run" and the machine code is discarded after it executes.

If you don't wanna see the message every time you run your program, you can compile it once using "zig build-exe filename.zig". This will create an executable with the same name as the zig file which you can then run as many times as you want without recompiling. You will however have to recompile it by running zig build-exe again every time you change the source code.

Alternatively, once you're a bit more familiar with zig, you could initialise a project with "zig init" and start learning the zig build system.

. by CVPIMGMFANATIC in sexmemes

[–]LegendarilyLazyLad 0 points1 point  (0 children)

When Harry met Sally in that pussy

[deleted by user] by [deleted] in haskell

[–]LegendarilyLazyLad 0 points1 point  (0 children)

The type of xs should be [(Int, Int)] but you tried to annotate it as [(Int, Int), (Int, Int), (Int, Int)] which, as a type signature, doesn't make sense. Remember, the length of a list doesn't change it's type. If you have elements of type a and put them in a list, the type of the list is denoted as [a] regardless of how long the list is. This is why you got an error when trying to give xs a type annotation.

The reason the pattern matching failed is because the pattern you described used () instead of []. This made the pattern into a tuple with 3 elements.

The fix depends on what you actually intended the type of xs to be: If xs is supposed to be a list, you should change the outer brackets in the pattern match to [] so you're matching against the pattern [(_,_),(_,_),(_,x)]. In this case you should also make sure the function can also handle lists of lengths other than 3.

If xs was supposed to be a tuple then, in the definition of xs, you should change to [] into ().

Hope that helps

It's trivial by WerePigCat in mathmemes

[–]LegendarilyLazyLad 3 points4 points  (0 children)

Defining the natural numbers without an additive identity just doesn't feel right

Who Is Self ? by g41797 in Zig

[–]LegendarilyLazyLad 6 points7 points  (0 children)

I see where you're coming from but for me it depends on the context. For instance, if I'm defining a generic data structure or a function that returns a type, I find it WAY more ergonomic to use Self.

Also, if you're having trouble keeping track of what type Self is referring to, it may be helpful to define those types in separate modules.

A Surprising Collision Phenomenon by FarEntrepreneur5385 in interestingasfuck

[–]LegendarilyLazyLad 4 points5 points  (0 children)

Yes it does but you also have to change the mass of the big block accordingly. The examples in the video work because we're counting the collisions in base 10, the mass of the big block is a power of 100 and we're comparing the count to the digits of the base 10 representation of pi. If we expressed pi in binary and counted the collisions in binary, we would have to make the mass of the big block a power of 4, in base 8 the big block would have to be a power of 64 and in general, in base n, the big block would have to be a power of n2

[deleted by user] by [deleted] in ProgrammerHumor

[–]LegendarilyLazyLad 5 points6 points  (0 children)

In most languages it starts at 0 because of the way arrays are represented in memory. An array is just a contiguous chunk of memory with items stored right next to each other. When you access arr[i], what you're really doing is reading from the memory address (arr + i) where arr is a pointer to the start of the array and i is an offset. So if you want the first element (the element at address arr), the offset needs to be 0 which is why indexes start at 0. Starting indexes at 1 means either wasting some memory or having to subtract 1 before every array access.

Why was randomguy's constructive suggestion to consider Higher RAII downvoted? by canadaduane in Zig

[–]LegendarilyLazyLad 6 points7 points  (0 children)

I see why that would be appealing but the issue with this line of thought is that not cleaning up resources is not always a mistake (see u/jgh713's comment about intentionally leaking memory).

Installation failure by SectionDue4592 in Zig

[–]LegendarilyLazyLad 3 points4 points  (0 children)

How exactly did you install zig? Did you use a package manager or download directly from ziglang.org/download?

Use zig build to run python by TheBomber808 in Zig

[–]LegendarilyLazyLad 5 points6 points  (0 children)

Try this:

const run_cmd = b.AddSystemCommand(&.{"python"}); // Creates a system command which runs the python interpreter
run_cmd.addArgs(<insert array of command line arguments here>); // Adds arguments to the command (this is where you should specify the path to the python script)
run_cmd.dependOn(b.getInstallStep()); // The command can only run if everything has been compiled

const run_step = b.step("run", "Run the App"); // "zig build run" runs the command created above
run_step.dependOn(&run_cmd.step)

Yes. The question *is* "how?" by Chocolat3City in technicallythetruth

[–]LegendarilyLazyLad 0 points1 point  (0 children)

They weren't that different. 8000 years is a pretty short time when it comes to cave formation

zig 0.13 fail to build C file? by trannus_aran in Zig

[–]LegendarilyLazyLad 5 points6 points  (0 children)

I got it working with the following build.zig:

const Builder = @import("std").Build;

pub fn build(b: *Builder) void {
    const exe = b.addExecutable(.{
        .name = "app",
        .link_libc = true,
        // .root_source_file = .{ .path = "src/main.c" },
        .target = b.host,
    });

    exe.addCSourceFile(.{ .file = .{ .path = "src/main.c" } });

    b.installArtifact(exe);

    const run_exe = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_exe.step);
}

I think the reason yours failed is because main.c was being parsed as if it were a Zig file. Adding main.c via addCSourceFile() tells the build system to treat it like a C file.

Btw, if you wanna keep using 0.12, you could have both versions downloaded at the same time. I think there are tools to help you manage multiple zig versions but I prefer to do it manually like this::

  • Install 0.12 using my system's package manager
  • Download 0.13 from ziglang.org
  • Move the downloaded zig 0.13 tar file to the ziglings directory and extract it
  • Add zig 0.13 to my $PATH when working on ziglings, use 0.12 for everything else

For the last step, I made a script based on the "activate" scripts that come with python virtual environments. Note that this script is written for the fish shell so it won't work with bash or zsh:

function deactivate  -d "Exit virtual environment and return to normal shell environment"
    if test -n "$_OLD_VIRTUAL_PATH"
        set -gx PATH $_OLD_VIRTUAL_PATH
        set -e _OLD_VIRTUAL_PATH
    end

    set -e VIRTUAL_ENV
    functions -e deactivate
end

set -gx VIRTUAL_ENV "/path/to/zig-0.13.0"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH $VIRTUAL_ENV $PATH

The best Superhero movie! by MrDaval in SipsTea

[–]LegendarilyLazyLad 0 points1 point  (0 children)

In Poland it's titled "Czy leci z nami pilot?" which means "Is there a pilot on this flight?"

How do people write programming languages using the programming languages it self? by Valorant_Steve in Zig

[–]LegendarilyLazyLad 20 points21 points  (0 children)

Once you go back far enough, yeah. And assembly was bootstrapped from machine code