ChezScheme icon indicating copy to clipboard operation
ChezScheme copied to clipboard

`~^` does not break out of `~{` loops

Open kg583 opened this issue 1 year ago • 0 comments

Per the CSUG,

Chez Scheme's implementation of format supports all of the Common Lisp [30] format directives except for those specific to the Common Lisp pretty printer.

However, the up-and-out/escape upward directive ~^ does not break out of ~{ loops:

If there are no more arguments remaining to be processed, then the immediately enclosing ~{ or ~< construct is terminated.

Instead, it simply skips the remainder of the ~{ construct, behaving identically to what the HyperSpec limits to the case of ~:{:

If ~^ is used within a ~:{ construct, then it terminates the current iteration step because in the standard case it tests for remaining arguments of the current step only; the next iteration step commences immediately. ~:^ is used to terminate the iteration process. ~:^ may be used only if the command it would terminate is ~:{ or ~:@{.

; Scheme
(format "~{~v,5^~:*~a ~}" (iota 10))
>>> 0 1 2 3 4 6 7 8 9

; Common Lisp
(format nil "~{~v,5^~:*~a ~}" (loop as i from 0 to 9))
>>> 0 1 2 3 4

I suppose this difference in implementation is compliant with what the CSUG says concerning format (i.e. the directive is "supported"), but it's a rather significant diversion from the HyperSpec (compared to Chez Scheme's other minor format differences) (and makes it harder to actually terminate loops).

kg583 avatar Dec 22 '24 08:12 kg583