ion-docs icon indicating copy to clipboard operation
ion-docs copied to clipboard

Clarify rules for repeat macro

Open popematt opened this issue 1 year ago • 1 comments

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 0 here 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 0 rather than potentially adding special logic to advance the reader appropriately when it is 0.

I'm inclined to say no.

Second question is should the n parameter be flex_uint::n?

popematt avatar Oct 11 '24 21:10 popematt

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.

popematt avatar Nov 20 '24 19:11 popematt