# hello.zig -rw-r--r-- 648 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const std = @import("std");
const c = @cImport(@cInclude("stdio.h")); // -lc

fn sum(comptime T: type, comptime a: T, b: T) T {
    return a + b;
}

test "two + two is four" {
    try std.testing.expectEqual(sum(i8, 2, 2), 4);
    try std.testing.expectEqual(sum(i8, 2, 2), 5);
}

fn getrnd() i32 {
    var rnd = std.Random.DefaultPrng.init(123);
    return std.Random.int(rnd.random(), i32);
}

pub fn main() void {
    const two: i8 = 1 + 1;
    const three = comptime sum(i32, 1, getrnd());
    const more = sum(i32, 1, c.fgetc(c.stdin));
    std.debug.print("Hello, {} {} {} {}\n", .{ two, sum(i32, @as(i32, 2000), getrnd()), three, more });
}