top | item 29157828

(no title)

dankoncs | 4 years ago

Cing through this, I can tell you that you can C C++: https://godbolt.org/z/sWETvsoKd (a demo for polymorphism in C90)

Not only can you do OOP in C, you can also do FP, implement your own iterators and the like. (Function) pointers are your friend: https://news.ycombinator.com/item?id=28378627#28406874

And remember: FP = pure functions (no side effects) + immutable values

Currying in C is essentially taking the address of a function pointer and not calling it. You can do lazy evaluation as well. The Cky is the limit!

Yes, C++ is comfy, but you cannot really do FP with its STL. As STL containers require mutability by default.

std::transform(v.begin(), v.end(), w.begin(), [](auto const& x){ /* ... */});

Transforming the contents of v requires a buffer(!) w. (The rescue: https://github.com/arximboldi/immer)

In Python, this would be something akin to:

map(lambda x: x, t); # t being a tuple type here

This will return another tuple.

Yeah, so these are just some pointers. I just wanted to stress that C can enable your creativity once you get the essence of it.

discuss

order

No comments yet.