Hacker News new | ask | show | jobs
by joshuamorton 3097 days ago
Sure, but at that point you've just reimplemented python in macros ;)

The other thing to note is that

    sorted([(k.weight, k.name) for k in somelist], reverse=True)
is essentially already typechecked:

    def biggest_ks(ks: K):
        return sorted([(k.weight, k.name) for k in ks], reverse=True)
The above code now has all the same type guarantees as your c++, actually maybe more since the macros you use are going to be...uhhh, mysterious.
1 comments

The macro would only be used to generate k for convenience. It could be all implemented in straight, macro-less C++98 in O(minutes).

My point was just that you can implement almost whatever you want (even without macros, they'll just expand the design space).

I don't see how you could implement the (k.attr).for_(k) part. That's essentially an assignment, a macro could maybe convert it to a lambda, but I don't see how it would be done macro-free.