News for hackers. Stuff that matters.
Re:Ask HN: Please Review My Metalanguage by JaumeGreen on Thursday February 09, 2023 @04:52AM (#34721754)
EDIT: I misunderstood how it works, read the reply to see why I was in the wrong.

I haven't read it all (and probably won't, these kinds of works are not my forte), but there's something that doesn't look that nice.

The swapped function seems strange, mostly because you treat 1 as a special case which reverses the content.

I would either have a reverse function or use negative numbers to reverse those chunks, like this:

    uint(16,0xc01f) matches big endian 0xc01f (bit sequence 1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1).
    swapped(8, uint(16,0xc01f)) (bit sequence 0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0).
    swapped(-16, uint(16,0xc01f)) (bit sequence 1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1).
    swapped(-8, uint(16,0xc01f)) (bit sequence 1,1,1,1,1,0,0,0, 0,0,0,0,0,0,1,1).
    swapped(-4, uint(16,0xc01f)) (bit sequence 0,0,0,0, 1,1,0,0, 1,1,1,1, 1,0,0,0).
There might be better solutions, I just dislike exceptions in rules, if it can be helped.
Re:Ask HN: Please Review My Metalanguage by kstenerud on Thursday February 09, 2023 @05:11AM (#34721882)
Swap reverses all bits in chunks of the granularity size. So given bits = ABCDEFGHIJKLMNOP, you get:

    swapped(8, bits) -> IJKLMNOPABCDEFGH
    swapped(4, bits) -> MNOPIJKLEFGHABCD
    swapped(2, bits) -> OPMNKLIJGHEFCDAB
    swapped(1, bits) -> PONMLKJIHGFEDCBA
So the full bit reversal when granularity = 1 is emergent phenomena rather than an exception.
Re:Ask HN: Please Review My Metalanguage by JaumeGreen on Thursday February 09, 2023 @05:33AM (#34722024)
Ok, that is more understandable. If there were some more examples in the page then this emergent behaviour could be seen faster.

Nothing to add then

Re:Ask HN: Please Review My Metalanguage by kstenerud on Thursday February 09, 2023 @06:03AM (#34722245)
Cool! Even this feedback is important. This document needs to be accessible and easy to grasp, otherwise it has a UX problem.