ion-docs
ion-docs copied to clipboard
Clarify rules for repeat macro
It's pretty obvious that something like this should be illegal:
(:repeat -2 true)
Should this be allowed?
(:repeat 0 true)
My thoughts are...
- It could be surprising either way.
- We're specifically not trying to make sure the macro system is suitable for general purpose computing. Disallowing
0here helps to make sure that you can't do something like(.if_none (.repeat (%x) '') "x is 0" "x is more than 0"). - In some implementations, it may be easier to implement the repeat macro if we can just raise an error for
0rather than potentially adding special logic to advance the reader appropriately when it is0.
I'm inclined to say no.
Second question is should the n parameter be flex_uint::n?
In https://github.com/amazon-ion/ion-tests/pull/133, we decided that a repeat of 0 is allowed, and confirmed that repeating an empty stream is also allowed.