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
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:
There might be better solutions, I just dislike exceptions in rules, if it can be helped.