Remix.run Logo
v_iter 14 hours ago

So, the point of this language is to be able to write code with high productivity, but with the benefit of compiling it to a low level language? Overall it seems like the language repeats what ZIG does, including the C ABI support, manual memory management with additional ergonomics, comptime feature. The biggest difference that comes to mind quickly is that the creator of Zen-C states that it can allow for the productivity of a high level language.

messe 13 hours ago | parent | next [-]

It has stringly typed macros. It's not comparable to Zig's comptime, even if it calls it comptime:

    fn main() {
        comptime {
            var N = 20;
            var fib: long[20];
            fib[0] = (long)0;
            fib[1] = (long)1;
            for var i=2; i<N; i+=1 {
                fib[i] = fib[i-1] + fib[i-2];
            }

            printf("// Generated Fibonacci Sequence\n");
            printf("var fibs: int[%d] = [", N);
            for var i=0; i<N; i+=1 {
                printf("%ld", fib[i]);
                if (i < N-1) printf(", ");
            }
            printf("];\n");
        }

        print "Compile-time generated Fibonacci sequence:\n";
        for i in 0..20 {
            print f"fib[{i}] = {fibs[i]}\n";
        }
    }
It just literally outputs characters, not even tokens like rust's macros, into the compiler's view of the current source file. It has no access to type information, as Zig's does, and can't really be used for any sort of reflection as far as I can tell.

The Zig equivalent of the above comptime block just be:

    const fibs = comptime blk: {
        var f: [20]u64 = undefined;
        f[0] = 0;
        f[1] = 1;
        for (2..f.len) |i| {
            f[i] = f[i-1] + f[i-2];
        }
        break :blk f; 
    };
Notice that there's no code generation step, the value is passed seamlessly from compile time to runtime code.
thomasmg 13 hours ago | parent | prev | next [-]

I wonder, how can a programming language have the productivity of a high-level language ("write like a high-level language"), if it has manual memory management? This just doesn't add up in my view.

I'm writing my own programming language that tries "Write like a high-level language, run like C.", but it does not have manual memory management. It has reference counting with lightweight borrowing for performance sensitive parts: https://github.com/thomasmueller/bau-lang

jhgb an hour ago | parent [-]

C is literally a high level language.

johnisgood 14 hours ago | parent | prev | next [-]

Nim is a high-level language as well and compiles to C.

the__alchemist 13 hours ago | parent [-]

Odin and Jai are others.

Voycawojka 13 hours ago | parent | next [-]

Does Odin compile to C? I thought it only uses LLVM as a backend

johnisgood 9 hours ago | parent | next [-]

No, Odin does not compile to C. It is a standalone programming language that compiles directly to machine code. It primarily uses LLVM as its backend for compiling to machine code, like you said.

sestep 10 hours ago | parent | prev [-]

Same question but for Jai.

9 hours ago | parent [-]
[deleted]
zem 11 hours ago | parent | prev [-]

chicken scheme compiles to c as well. it's a pretty convenient compilation target, you get to use all the compilers and tool chains out there and you don't add a dependency on llvm

dieggsy 10 hours ago | parent [-]

I love CHICKEN Scheme! Nice to see it mentioned. Though I think it's worth pointing out it compiles to something pretty far from handwritten C, to my understanding. I think this is true of both performance and semantics; for example you can return a pointer to a stack allocated struct from a foreign lambda (this is because chicken's generated C code here doesn't really "return", I think. Not an expert).

Of course you can always drop to manually written C yourself and it's still a fantastic language to interop with C. And CHICKEN 6 (still pre-release) improves upon that! E.g structs and Unions can be returned/passed directly by/to foreign functions, and the new CRUNCH extension/subset is supposed to compile to something quite a bit closer to handwritten C; there are even people experimenting with it on embedded devices.

jrapdx3 8 hours ago | parent | next [-]

Chicken indeed interoperates with C quite easily and productively. You're right that the generated C code is mostly incomprehensible to humans, but compiles without difficulty.

The Chicken C API has functions/macros that return values and those that don't return. The former include the fabulous embedded API (crunch is an altogether different beast) which I've used in "mixed language" programming to good effect. In such cases Scheme is rather like the essential "glue" that enables the parts written in other languages to work as a whole.

Of course becoming proficient in Scheme programming takes time and effort. I believe it's true that some brains have an affinity for Lispy languages while others don't. Fortunately, there are many ways to write programs to accomplish a given task.

zem 9 hours ago | parent | prev [-]

> this is because chicken's generated C code here doesn't really "return", I think. Not an expert.

not an expert either, but you're right about that, it uses cps transformations so that functions never return. there's a nice write up here: https://wiki.call-cc.org/chicken-compilation-process#a-guide...

kuon 13 hours ago | parent | prev | next [-]

I am working on mine as well. I think it is very sane to have some activity in this field. I hope we will have high level easy to write code that is fully optimized with very little effort.

echelon 13 hours ago | parent | prev [-]

There are going to be lots of languages competing with Rust and Zig. It's a popular, underserved market. They'll all have their unique angle.

pjmlp 13 hours ago | parent | next [-]

I has been served for several decades, however since the late-90's many decided reducing to only C and C++ was the way going forward, now the world is rediscovering it doesn't have to be like that.

forgotpwd16 12 hours ago | parent | prev [-]

They're are certainly going to be lots of languages because now with LLMs it's easier (trivial?) to make one + library (case in point: just within last month there're have been posted here ~20 new langs with codebases 20k~100k LOC) but don't really see them competing. Rust and Zig brought actual improvements and are basically replacing usecases that C++/C had limiting the space available to others.