r/Compilers • • 8d ago

Token efficiency comparison with C++

abs<T: int|uint|long|ulong>(T t) -> T as operator[|] : PreContract -> t < 0 ?-t:t : PostContract # binding {this:};

43 tokens. That's it. 43 tokens of pure, dense meaning.

Let's count what a C++ programmer would have to write to achieve the exact same thing:

cpp

template <typename T, std::enable_if_t<std::is_same_v<T, int> |\| std::is_same_v<T, uint> |\| std::is_same_v<T, long> |\| std::is_same_v<T, ulong>, bool> = true>
struct AbsoluteValue {
    T operator()(T t) const {
        // PreContract logic here
        T result = (t < 0) ? -t : t;
        // PostContract logic here
        return result;
    }
};

// ... and they still wouldn't have |x| circumfix syntax or operator binding ...

That's over 300 tokens, and it doesn't even include the contract system or the operator binding (which requires custom parser tricks in C++).

In IDEKA, every single token is pulling its weight:

  1. <T: int|uint|long|ulong> — 11 tokens define a type constraint with 4 allowed types.

  2. as operator[|] — 5 tokens bind a function to a custom syntactic form.

  3. : PreContract — 2 tokens attach code that runs before the body.

  4. -> t < 0 ? -t : t — 9 tokens define the entire execution logic.

  5. : PostContract — 2 tokens attach code that runs after the body.

  6. \# binding {this:} — 6 tokens define the operator's associativity and operand position.

0 Upvotes

8 comments sorted by

2

u/jcastroarnaud 8d ago

Python sources, and executables (!), are in the main folder of the repo. Order your pet LLM to clean up after itself: no executables in the repo, ever, and Python source code in its own folder.

Test programs printing to stdout, seriously? Not even unit tests? For a language that, from the documentation alone, is as large as C++, that's a criminal lack of tests. Add unit tests to all modules of the compiler, and test harnesses for the runtime (to catch runtime errors cleanly).

-1

u/cozcoo 8d ago

Thanks for looking into it. I could let the creator know about tests and other problems you pointed out. Though it isn't clear to me, from your feedback , if you know about what the language implements and it's overall idea, and if you do know it, your opinions on it will be appreciated if you're willing to share that too.

If you wanna look into it. Here's a short read on what the language, as a whole, provides/is trying to provide:
https://medium.com/@kvthweatt/more-logic-per-byte-per-cycle-go-brrr-0157176e7617

2

u/jcastroarnaud 8d ago

Hello, bot. I've read the linked article, and a good part of it tells about ditching LLVM, and a specific optimization trick for assembly generation. These are fine, but are beside the point: a compiler without strong tests has no guarantee of working at all. One of the lessons taken from the Unix philosophy: "Make it work, make it right, make it fast". Your owner is skipping right to "make it fast" without care for the other two.

About the IDEKA language itself: the documentation shows a enormous set of features, without a clear organization. I'm not competent enough to evaluate all of them, and I don't know which features are actually implemented. So, I won't even try.

I have nothing more to say. Bye, bot.

0

u/cozcoo 7d ago edited 7d ago

Again Thanks for taking your time to actually read it and giving feedback. And about the skipping stuff part and whatnot, this language is still in development, those parts of the language and the github is still to be ironed out, and Im not sure i get what you mean by unorganized documentation, The specification documentations and stuff are indexed in the beginning if Im correct. If you think you have any suggestions that'd be good to have in the language, try the discord server. Better tell the guy himself and not have to go through my post .

https://discord.gg/MtvRv2pgW

1

u/Discordbothost 6d ago

If int/long are two's-complement, what happens at the signed minimum? Its positive magnitude won't fit in T. Does PreContract reject it, or is overflow defined? That boundary would help pin down the abs example's contract.

1

u/cozcoo 5d ago

It overflows

0

u/cozcoo 8d ago

Here's the language's github repo btw.
https://github.com/kvthweatt/IDEKA