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

Ltac2: provide access to boxing API in printf #18923

Open
MSoegtropIMC opened this issue Apr 11, 2024 · 1 comment
Open

Ltac2: provide access to boxing API in printf #18923

MSoegtropIMC opened this issue Apr 11, 2024 · 1 comment
Labels
kind: wish Feature or enhancement requests.

Comments

@MSoegtropIMC
Copy link
Contributor

Is your feature request related to a problem?

It is hard to structure large Ltac2 output, because it does not provide access to the boxing / formatting mechanisms of the pretty printer. Using newlines in printf leads to strange indenting.

Here is an example:

Require Import Ltac2.Ltac2.
Require Import Ltac2.Printf.

Ltac2 string_newline () := String.make 1 (Char.of_int 10).
Ltac2 Notation nl := string_newline ().

Ltac2 coq_terms_1 () := '(forall (a b : nat), a+b=b+a).
Ltac2 coq_terms_2 () := '(forall (a b : nat), (((((((a+b=b+a /\ a+b=b+a) /\ a+b=b+a) /\ a+b=b+a) /\ a+b=b+a) /\ a+b=b+a) /\ a+b=b+a) /\ a+b=b+a) /\ True).

(* why is there an extra new line after every 2nd line *)
Ltac2 Eval printf "%t%s%t%s%t%s%t%s" (coq_terms_1 ()) nl (coq_terms_1 ()) nl (coq_terms_1 ()) nl (coq_terms_1 ()) nl .

(* here the indenting gets really weird for each other term *)
Ltac2 Eval printf "%t%s%t%s" (coq_terms_2 ()) nl (coq_terms_2 ()) nl .

the output is:

(forall a b : nat, a + b = b + a)
(forall a b : nat, a + b = b + a)

(forall a b : nat, a + b = b + a)
(forall a b : nat, a + b = b + a)

- : unit = ()
(forall a b : nat,
 (((((((a + b = b + a /\ a + b = b + a) /\ a + b = b + a) /\ a + b = b + a) /\
     a + b = b + a) /\ a + b = b + a) /\ a + b = b + a) /\
  a + b = b + a) /\ True)
(forall a b : nat,
                           (((((((a + b = b + a /\ a + b = b + a) /\
                                 a + b = b + a) /\
                                a + b = b + a) /\
                               a + b = b + a) /\ a + b = b + a) /\
                             a + b = b + a) /\ a + b = b + a) /\ True)

- : unit = ()

Proposed solution

Ltac2 could provide a set of message objects which correspond to the formatting tokens described in:

https://coq.inria.fr/doc/V8.19.0/refman/user-extensions/syntax-extensions.html#use-of-notations-for-printing

One can then combine these with content via Message.concat.

Alternative solutions

Provide (backslash) escapes for formatting in in printf format strings. This would also make sense in addition to the above.

Additional context

See Zulip discussion

https://coq.zulipchat.com/#narrow/stream/278935-Ltac2/topic/Unexpected.20indenting.20of.20coq.20terms

@MSoegtropIMC MSoegtropIMC added needs: triage The validity of this issue needs to be checked, or the issue itself updated. kind: wish Feature or enhancement requests. labels Apr 11, 2024
@SkySkimmer SkySkimmer removed the needs: triage The validity of this issue needs to be checked, or the issue itself updated. label Apr 24, 2024
SkySkimmer added a commit to SkySkimmer/coq that referenced this issue Apr 29, 2024
cf coq#18923 (not sure we want to close without also interpreting format strings)
@SkySkimmer
Copy link
Contributor

#18988

SkySkimmer added a commit to SkySkimmer/coq that referenced this issue May 2, 2024
cf coq#18923 (not sure we want to close without also interpreting format strings)
SkySkimmer added a commit to SkySkimmer/coq that referenced this issue May 2, 2024
cf coq#18923 (not sure we want to close without also interpreting format strings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: wish Feature or enhancement requests.
Projects
None yet
Development

No branches or pull requests

2 participants