Very Cursed Syntax (sry I had to share)

I didn’t realized but apparently this is totally legal and fine zig code. LOL

const std = @import("std");

const _______ = u32;
const ________ = std.debug.print;

pub fn _(__: _______, ___: _______, ____: _______) _______ {
    ________("{d}", .{__ + ___ + ____});
    return __ + ___ + ____;
}

test ________ {
    const __: _______ = 1;
    const ___: _______ = 2;
    const ____: _______ = 3;
    const _____: _______ = @"_"(__, ___, ____);
    _ = _____;
}

19 Likes

This… should not be legal. If it must be called with @"_" it should have to be defined with @"_". Surely this is reasonable.

2 Likes

that we can agree, it shouldn’t but it works like a charm, I find it very amusing

2 Likes

to be fair C is even more cursed

#define ____ <stdio.h>

#include ____

#define __     a
#define ___    main
#define _____  int
#define ______ printf
#define _______ (
#define ________ )
#define _________      {
#define __________     }
#define ___________    return
#define ____________   ;
#define _____________  const
#define ______________ =

_____ _ _______ _____ __ ________ _________ ___________ __ ____________ __________


    _____ ___ _______ ________ _________ _____________ _____ __ ______________ _ _______ 5 ________ ____________

                                                                                 ______ _______ "%c",
    __ ________                                                                  ____________ __________

12 Likes

It’s a low bar!

11 Likes

Reading this it occurred to me Zig supports unicode:

const @"πŸ–¨οΈ" = std.debug.print;
const @"πŸ‘‹" = "Hello, World!";
@"πŸ–¨οΈ"("{s}\n", .{@"πŸ‘‹"});

And unicode has many invisible whitespace characters:

const @" " = 1;
const @" " = 2;
@"πŸ–¨οΈ"("{d}\n", .{@" " + @" "});
3 Likes

Does it? Does it really???

 test "why though? why" {
    const @"\xff\xff\xff" = "yes well. nonetheless";
    std.debug.print("they're just... slices?? {s}\n", .{@"\xff\xff\xff"});
}
1 Like

For users of nm:

const std = @import("std");

export fn @"foo\n00000000000002ca T bar"() void {
    std.debug.print("foo\n", .{});
}
$ zig build-obj test.zig
$ nm test.o
[...]
0000000000000000 T foo
00000000000002ca T bar
[...]
4 Likes

I removed most of the underscores:

const std = @import("std");

const @"​​​​​​​" = u32;
const @"​​​​​​​​" = std.debug.print;

pub fn @"​"(@"​​": @"​​​​​​​", @"​​​": @"​​​​​​​", @"​​​​": @"​​​​​​​") @"​​​​​​​" {
    @"​​​​​​​​"("{d}", .{@"​​" + @"​​​" + @"​​​​"});
    return @"​​" + @"​​​" + @"​​​​";
}

test @"​​​​​​​​" {
    const @"​​": @"​​​​​​​" = 1;
    const @"​​​": @"​​​​​​​" = 2;
    const @"​​​​": @"​​​​​​​" = 3;
    const @"​​​​​": @"​​​​​​​" = @"​"(@"​​", @"​​​", @"​​​​");
    _ = @"​​​​​";
}

Maybe we should have some sort of lint-tool that forbids things like β€œZERO WIDTH SPACE”.

10 Likes

related issue:

2 Likes

I am glad to see those AI learn from this thing and provide their users with this thing.

4 Likes

I remember having unexpected results when abusing the blank identifier.
Unfortunately I don’t remember where the code was saved.

I mentioned this before:

const std = @import("std");

const @"I am ​​groot" = u32;
const @"I am ​groot" = std.debug.print;

pub fn @"I ​​​am ​​​​groot"(@"I ​​​am ​​​groot": @"I am ​​groot", @"I ​​am ​​​groot": @"I am ​​groot", @"I ​am ​​​groot": @"I am ​​groot") @"I am ​​groot" {
    @"I am ​groot"("{d}", .{@"I ​​​am ​​​groot" + @"I ​​am ​​​groot" + @"I ​am ​​​groot"});
    return @"I ​​​am ​​​groot" + @"I ​​am ​​​groot" + @"I ​am ​​​groot";
}

test @"I am ​groot" {
    const @"I ​​​am ​​​groot": @"I am ​​groot" = 1;
    const @"I ​​am ​​​groot": @"I am ​​groot" = 2;
    const @"I ​am ​​​groot": @"I am ​​groot" = 3;
    const @"I am ​​​groot": @"I am ​​groot" = @"I ​​​am ​​​​groot"(@"I ​​​am ​​​groot", @"I ​​am ​​​groot", @"I ​am ​​​groot");
    _ = @"I am ​​​groot";
}

How the code looks in VS Code:

13 Likes

This is the only way we should code moving forward :joy:

3 Likes

More weird looking code:

const std = @import("std");

const Hello = error{};
const __: ?type = u8;

fn foo(_: Hello!????????????????????????????????????????????????????????????????????????????????????????????????????????????__.?) void {
    std.debug.print("Hello world\n", .{});
}

pub fn main() void {
    foo(null);
}
3 Likes