Skip to main content
Glama
advanced-test-mistral-latest-2025-10-26T12-31-21-708Z.md3.76 kB
# Advanced Zig Test Report **Model**: mistral:latest **Date**: 2025-10-26T12:31:21.708Z **Total Tests**: 6 **Passed**: 6 **Failed**: 0 **Average Response Time**: 31.16s ## Results ### 1. Basic Zig Syntax [EASY] **Status**: ✅ PASS **Time**: 25.82s **Response**: ```zig Here is a simple Zig function in Zig language that calculates the sum of two integers: ```zig pub fn main() !void { const a = 5; const b = 10; const sum = add(a, b); std.debug.print("The sum is: {}", .{sum}); } pub u64 add(u64 a, u64 b) !u64 { return a + b; } ``` In this code, the `main` function initializes two constants named `a` and `b`, then calls the `add` function to compute their sum. The `add` function takes two unsigned 64-bit integers as arguments and returns th ``` ### 2. Memory Allocation [EASY] **Status**: ✅ PASS **Time**: 26.21s **Response**: ```zig In Zig, you can use the `std` library to allocate and manage memory dynamically. Here's a simple example of how to allocate memory for an integer, store a value, and free it. ```zig const std = @import("std"); pub fn main() !void { var heap_allocated_int: *u64; try _ = std.heap.alloc(ref heap_allocated_int); // Store an integer in the allocated memory try _ = heap_allocated_int.init(123); // Use the stored integer var my_integer: u64 = cast![*u64; heap_allocated_int] ``` ### 3. Error Handling [MEDIUM] **Status**: ✅ PASS **Time**: 28.60s **Response**: ```zig In Zig, the `Result` type is not built-in but can be easily defined using an enum and a struct. Here's an example of how you could create a simple `Result` type and a function that returns a `Result`. The error handling in the caller will be demonstrated as well. ```zig const std = @import("std"); pub enum Result { Ok(anything), Err(err: &str), } pub fn myFunction(input: u8) !Result { if input > 10 { return .Ok(format!("Success with input {}", input)); } return .E ``` ### 4. Structs & Methods [MEDIUM] **Status**: ✅ PASS **Time**: 19.03s **Response**: ```zig In Zig language, I'll create a struct for a Point with `x` and `y` coordinates, and also include a function to calculate the distance from the origin (0, 0). ```zig const Point = struct { x: f64, y: f64, }; fn distFromOrigin(point: const *Point) f64 { var distance = point.x*point.x + point.y*point.y; return Math.sqrt(distance); } ``` Here's how you can use the Point struct and the `distFromOrigin` function in your code: ```zig const myPoint = Point{ 3.0, 4.0 }; print("Distan ``` ### 5. Generics [HARD] **Status**: ✅ PASS **Time**: 43.35s **Response**: ```zig In Zig, you can create a generic function for finding the maximum of two values using templates. Here's an example of how to write such a function: ```zig const fn max = template <typ T> func (a: T, b: T) -> T { if (a > b) { return a; } return b; } ``` In this example, the `max` function is defined as a generic function with the template parameter `T`, which represents the numeric type. The function takes two arguments of type `T` and returns their maximum value. You can ``` ### 6. Comptime Magic [HARD] **Status**: ✅ PASS **Time**: 43.92s **Response**: ```zig To implement a compile-time factorial computation using `comptime` in Zig, you can follow the steps below: 1. First, make sure you have Zig installed on your system. If not, you can find installation instructions here: https://ziglang.org/install/ 2. Create a new Zig project by running the following command: ```sh zig init --lang=Zig factorial_ct cd factorial_ct ``` 3. Next, open the main source file `src/main.zig`. Then, add the required header and dependencies for `comptime`: ```zig cons ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fulgidus/zignet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server