datatype99
Cloak
datatype99 | Cloak | |
---|---|---|
29 | 4 | |
794 | 889 | |
- | - | |
3.5 | 0.0 | |
27 days ago | about 4 years ago | |
C | C | |
MIT License | - |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
datatype99
-
Future of high-level languages
Sum types and pattern matching have already been hacked together in a preprocessor macro in C; see https://github.com/Hirrolot/datatype99.
- So far there is no evidence that Rust adds any value here. And if C is missing certain features, they can be added.
-
Does C have an equivalent to an algebraic data type?
It does not. There are people who have implemented such constructs in C code however, for example: https://github.com/Hirrolot/datatype99
-
Memory Management Reference
Nice reference but with some strange bits:
> Algebraic data types are usually represented using a heap. Because of their non-uniformity, algebraic data types are more difficult to scan.
Using a heap??? We can represent ADTs using stack as well, that's what we usually do in C and Rust.
Shameless plug: https://github.com/Hirrolot/datatype99 (a library of mine that generates type-safe ADTs for pure C99).
-
Pretty-Printable Enumerations in Pure C
I agree; I would especially not recommend abusing macros throughout an application codebase too much. Conceptually, Metalang99 is more of a (sub)language than a library, which also adds some entry barrier. Ideally, I see the application of Metalang99 being used "behind the scenes", e.g., encapsulated in separate code files/libraries such as Datatype99 and Interface99. This is what I (mostly) do in SmolRTSP.
-
lipstick: a Rust-like syntax frontend for C
I've done something similar with Datatype99 and Interface99. They are like a macro eDSL that compiles to C. The first one features algebraic data types, the second one features interfaces.
-
Any alternative to vala?
If you need a bit more high-level constructions, you can use the Datatype99 and Interface99 libraries. The former provides polymorphism over data, the latter -- over behaviour (I am the creator of these libraries).
-
Syntatic Sugar that compiles to C
OP, you might find datatype99 and its sibling projects interesting, though they mostly leverage the C preprocessor without going all the way towards defining a new language.
-
AST Implementation in C
You can use Datatype99 to represent your AST tagged union conveniently.
-
Rust for Linux Redux
Compared to plain C, you have ADTs which help from day to day programming. You can bring them to C (https://github.com/Hirrolot/datatype99) but I don't know if the Linux guys would allow it.
Cloak
-
Object-oriented Programming with ANSI-C [pdf]
Where cloak.h is https://github.com/pfultz2/Cloak/blob/master/cloak.h
The above macros are admitttedly very hairy. If C had a better preprocessor, but was otherwise unchanged, they could look a lot nicer.
> I never said such a thing. Would appreciate if you didn't put words in my mouth.
A normal part of dialogue is, "I'm going to repeat your point back to you in my own words, and you can either agree with my restating of it, or point out at which point I've misunderstood you". That's what I was doing. "Would appreciate if you didn't put words in my mouth" is unnecessary hostility.
> In my concrete example, given that FILE and DIR were classified as objects, to which of the so-called objects does F(const char*, FILE, DIR) belong?
Take any language which you agree is "OO". Add one new feature (if it isn't already there): functions/methods which don't belong to any class/object. Now the function you are talking about is possible in that language. Did the language thereby suddenly cease to be OO when we added that feature? Most people would disagree with "Yes". But if "No", what is the actual difference between C and that language?
-
Plain C API design, the real world Kobayashi Maru test
> I use this pattern so much I actually wrote a little metaprogramming language that is capable of generating a lot of the boilerplate for you. Link in my bio, if anyone's interested in looking at it.
Your language [0] is an interesting idea. I've done a lot of similar stuff (not at work, I'm very rarely asked to write C code professionally, but I like mucking around with it in my personal time). My own approach to C metaprogramming involves obtuse preprocessor hacks (e.g [1]) and shell scripts that use grep/awk/sed to find macro invocations and spit out new header files as a result. Maybe your way is better.
A word of warning though – do you realise your name for your language is an anti-gay slur in several dialects of English? You might end up unintentionally upsetting some people with it.
[0] https://github.com/scallyw4g/poof
[1] https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,...
- Pretty-Printable Enumerations in Pure C
-
Datatype99: C99 with Sum Types, v0.1.0
Well, mostly I use idioms from the Cloak Wiki (https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,...). It takes some time to realise them :)
What are some alternatives?
metalang99 - Full-blown preprocessor metaprogramming
xcc - Toy C compiler for x86-64/aarch64/riscv64/wasm
zig - General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
libGimbal - C17-based extended standard library, cross-language type system, and unit testing framework targeting Sega Dreamcast, Sony PSP and PSVita, Windows, Mac, Linux, Android, iOS, and WebAssembly.
corrode - C to Rust translator
website-meta-language - An old offline HTML preprocessor (which can be used for static site generation), written in Perl and C that is still maintained for legacy reasons, but probably not recommended for new sites.
llvm-cbe - resurrected LLVM "C Backend", with improvements
cdecl - Composing and deciphering C (or C++) declarations or casts, aka ‘‘gibberish.’’
epilepsy - A functional language for C99 preprocessor metaprogramming [Moved to: https://github.com/Hirrolot/metalang99]
interface99 - Full-featured interfaces for C99
lisp-preprocessor - Common lisp embedded template engine
COS - C Object System: a framework that brings C to the level of other high level programming languages and beyond