Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~^ does not break out of ~{ loops #898

Open
kg583 opened this issue Dec 22, 2024 · 0 comments
Open

~^ does not break out of ~{ loops #898

kg583 opened this issue Dec 22, 2024 · 0 comments

Comments

@kg583
Copy link

kg583 commented Dec 22, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant