Live data from Hacker News

Show HN: The C3 programming language (C alternative language)

github.com

111–120 of 192 posts

Re: Show HN: The C3 programming language (C alternative language)

#111
post #97

Earlier quoted context omitted.

I don't like to say "never", because other things make change that invalidates previous conclusions. For example, let's say that for some reason macros were removed (this is very unlikely to happen, but as a thought experiment), then the symmetry between macro/fn definitions wouldn't be an argument anymore, and the question could be revisited. Similar things have happened before: the optional type syntax changed from…

Thank you. I am not going to have "fn" stop me from trying out C3 anyways. There is a C (single header-only) library[1] that determines CPU features at runtime (similar to that of what libsodium does), so I might try to use that with C3 and implement BLAKE2. That might be a good starting point, or perhaps even TOTP, my friend told me implementing TOTP might give me some insight into the language, but for that I will…

For grabbing the CPU features, there is some rudimentary implementation for x86 here: https://github.com/c3lang/c3c/blob/master/lib/std/core/priva... but not properly tested (which is to say, I would not count on it to work properly).

The `@require` here is creating a contract. You can't give a padding that is 0xFF, that's a programming error. However, you might have data which is invalid – in that case the typical error is INVALID_CHARACTER. To pass in a too small buffer is a programming error since the output buffer must be calculated first, so that's why that is not an error either. This was a deliberate change to make the API tighter.

So it's quite possible to add an "INVALID_LENGTH" error, but that should only be there in case one does encryption / decryption where the length cannot be easily determined beforehand i.e. it's part of the unknown input which the function determines. But in the Base32 implementation this is not the case. Either use it with an allocator for it to allocate sufficient memory for the data, or calculate that the buffer you pass in is big enough (or run into asserts if it isn't)

Re: Show HN: The C3 programming language (C alternative language)

#112
post #97

Earlier quoted context omitted.

I don't like to say "never", because other things make change that invalidates previous conclusions. For example, let's say that for some reason macros were removed (this is very unlikely to happen, but as a thought experiment), then the symmetry between macro/fn definitions wouldn't be an argument anymore, and the question could be revisited. Similar things have happened before: the optional type syntax changed from…

Thank you. I am not going to have "fn" stop me from trying out C3 anyways. There is a C (single header-only) library[1] that determines CPU features at runtime (similar to that of what libsodium does), so I might try to use that with C3 and implement BLAKE2. That might be a good starting point, or perhaps even TOTP, my friend told me implementing TOTP might give me some insight into the language, but for that I will…

If you want to have your own Base32 where giving a padding = 0xFF instead returns an error, it's commonplace to have a wrapper that will explicitly do the check and return an error if it fails, and otherwise call the function:

    macro String? encode2(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD)
    {
        if (padding >= 0xFF) return INVALID_PADDING?;
        return encode(allocator, src, padding, alphabet);
    }
Maybe a better place to ask these questions are on the Discord if you have an account: https://discord.gg/qN76R87

Re: Show HN: The C3 programming language (C alternative language)

#113
post #96

Earlier quoted context omitted.

Now I'm confused, what do you mean? What grammar changes?

Imagine v2.0 introduces a new feature that requires a parser change—one that v1.0 wouldn't be able to parse. $if $defined(C3_V2_PLUS): // new feature fn f = \ -> foo(); // this won't parse in v1.0 $else Callback f = ...; $endif This is also an issue if a future version of C3 introduces language level support, allowing newer compilers to compile code as if it were written for an earlier version. While this approach wo…

Ah, that is indeed true. However, the plan is to have the language fixed at 1.0, only updating stdlib and tooling after that.

Re: Show HN: The C3 programming language (C alternative language)

#114
post #110

Earlier quoted context omitted.

> distinguish between "this is a member access on an object" and "this is referencing something in a module". zig: what's the difference?

Surely Zig differentiates between, say, a function in a module, and a member on an object? Or are "modules" literally just instances of classes or something?

No, they are the same.

Re: Show HN: The C3 programming language (C alternative language)

#115
post #96

Earlier quoted context omitted.

Now I'm confused, what do you mean? What grammar changes?

Imagine v2.0 introduces a new feature that requires a parser change—one that v1.0 wouldn't be able to parse. $if $defined(C3_V2_PLUS): // new feature fn f = \ -> foo(); // this won't parse in v1.0 $else Callback f = ...; $endif This is also an issue if a future version of C3 introduces language level support, allowing newer compilers to compile code as if it were written for an earlier version. While this approach wo…

You don't need an ifdef.

You just need a CLI option like java's --source, where you specify the source compatibility with different language versions.

Re: Show HN: The C3 programming language (C alternative language)

#116
I think any system language going forward really needs three things:

1. Generics / templates

2. Destructors

3. Ownership

It is unfortunate that this only has the first one. There was a language called clay that had all three and kept easy integration with the C ABI, but it seems like that design has been lost.

Re: Show HN: The C3 programming language (C alternative language)

#117
post #111

Earlier quoted context omitted.

Thank you. I am not going to have "fn" stop me from trying out C3 anyways. There is a C (single header-only) library[1] that determines CPU features at runtime (similar to that of what libsodium does), so I might try to use that with C3 and implement BLAKE2. That might be a good starting point, or perhaps even TOTP, my friend told me implementing TOTP might give me some insight into the language, but for that I will…

For grabbing the CPU features, there is some rudimentary implementation for x86 here: https://github.com/c3lang/c3c/blob/master/lib/std/core/priva... but not properly tested (which is to say, I would not count on it to work properly). The `@require` here is creating a contract. You can't give a padding that is 0xFF, that's a programming error. However, you might have data which is invalid – in that case the typical e…

Oh thank you, that cpu_detect.c3 is exactly what I need, the posted single-header library is almost the same in terms of functionality.

BTW my last question still stands, however, that if there is a C library that is only a single header file that implements functions through macros, can it be used from C3? In C, for what I posted, you would need to first do "#define CPUDETECT_IMPL" and then include the header file. Could it be done from C3 somehow? As in, could this (or any) single-header library be used from C3?

And regarding the errors, can I have something like "Error" (in Odin), or an enum of errors? Sorry for this silly question, I realize I will have to read the source code of the libraries first.

Thank you for your help!

Re: Show HN: The C3 programming language (C alternative language)

#118

Earlier quoted context omitted.

Imagine v2.0 introduces a new feature that requires a parser change—one that v1.0 wouldn't be able to parse. $if $defined(C3_V2_PLUS): // new feature fn f = \ -> foo(); // this won't parse in v1.0 $else Callback f = ...; $endif This is also an issue if a future version of C3 introduces language level support, allowing newer compilers to compile code as if it were written for an earlier version. While this approach wo…

You don't need an ifdef. You just need a CLI option like java's --source, where you specify the source compatibility with different language versions.

You do, that's the point here. You need ifdefs in this example to selectively compile the same code with different compilers, or different language levels with the same compiler. In either case C3 will fail while parsing a newer feature with an older compiler or lang level.

Re: Show HN: The C3 programming language (C alternative language)

#119
post #113

Earlier quoted context omitted.

Imagine v2.0 introduces a new feature that requires a parser change—one that v1.0 wouldn't be able to parse. $if $defined(C3_V2_PLUS): // new feature fn f = \ -> foo(); // this won't parse in v1.0 $else Callback f = ...; $endif This is also an issue if a future version of C3 introduces language level support, allowing newer compilers to compile code as if it were written for an earlier version. While this approach wo…

Ah, that is indeed true. However, the plan is to have the language fixed at 1.0, only updating stdlib and tooling after that.

Well, if your language gains traction that plan may not succeed. For your sake, I hope that's the case :)

Re: Show HN: The C3 programming language (C alternative language)

#120
post #46
post #22

Earlier quoted context omitted.

As the author, let me add something beyond the comparison. Zig and Odin are very different languages, Odin is – as its slogan goes - "for the Joy of Programming". Zig on the other hand doesn't feel that this is a goal. From what I can tell Zig fans like to wrestle with the features of Zig to figure out how to fit their solutions within the constraints of the language. A mental challenge, similar to that of fighting t…

Just to be clear, I don't mean the description of Zig to put down the language or the community. It's the best I can do to describe the difference between Zig on one hand and Odin/C3 on the other. A more concrete example that might explain it better is looking at Advent of Code solutions. One thing that struck me was that doing typical tasks for parsing would be 2-3 functions stringed together in a smart way in the Z…

In other words, Zig is closer to the original C and maybe Scheme, while C3 and Odin tend towards maybe Ruby (while of course remaining capable of doing low-level stuff). Correct?
Post reply on HN