253

With a bit of fiddeling you can use every kind of bracket to basically make function calls in c++

Here are the links to the snippets, all compile and run

Rust: https://godbolt.org/z/bM3d7bG14

OCaml: https://godbolt.org/z/17oMv83zx

C++: https://godbolt.org/z/9Y3WfoE1W

you are viewing a single comment's thread
view the rest of the comments
[-] calcopiritus@lemmy.world 23 points 1 week ago* (last edited 1 week ago)

Funny that you put rust as the "uses parenthesis for function calls". When in rust you can use any bracket for macro invocations:

let v1 = vec!(1,2,3);
let v2 = vec![1,2,3];
let v3 = vec!{1,2,3};

These are valid and have the exact same meaning.

[-] Flipper@feddit.org 9 points 1 week ago

To be fair, with Rust macros anything goes. There was an example where someone demoed descriping rust structs and enums nested as xml with a macro to parse it.

[-] Ephera@lemmy.ml 5 points 6 days ago

I always enjoy this one: https://crates.io/crates/inline-python

Apparently, Python's syntax is almost entirely a subset of Rust's syntax + a few keywords, so even though you have to pass valid Rust tokens into a macro, that's good enough to write Python with just a few quirks.

[-] calcopiritus@lemmy.world 7 points 1 week ago

That's inside the macro though. Whatever you parse inside the macro is defined by the creator of the macro. The macro invocation itself is defined by the rust language.

Rust allows you to use any bracket because it doesn't know what the macro is supposed to do.

Some macros work like functions:

println!("Hello world");

Some macros work like array declarations:

let v = vec![1,2,3];

And some macros work like a code scope:

select!{
 a => myfunc(),
 b => my_other_func()
}

Since rust doesn't know what your macro does, it just lets the user choose whatever the user sees more fitting for that specific macro invocation.

[-] ExperimentalGuy@programming.dev 3 points 1 week ago

That's always funny to me. In a language that's so particular about different syntax features, they let macros of all things have a little bit of arbitrariness.

[-] Ephera@lemmy.ml 1 points 5 days ago

Yeah, I always wonder, if it was an intentional decision or just some first draft that stayed in.

Because I do think, it's kind of smart. Some macros make sense to call with either () or {}, depending on if you pass a code snippet that's multi-line or not.
So, you could come up with a complicated syntax to define which bracket types are acceptable, or you could just not bother. ๐Ÿ™ƒ

this post was submitted on 30 Oct 2026
253 points (98.1% liked)

Programmer Humor

33999 readers
183 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS