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

Printf.ksprintf could call the continuation on %! #7756

Closed
vicuna opened this issue Mar 19, 2018 · 12 comments
Closed

Printf.ksprintf could call the continuation on %! #7756

vicuna opened this issue Mar 19, 2018 · 12 comments

Comments

@vicuna
Copy link

vicuna commented Mar 19, 2018

Original bug ID: 7756
Reporter: @dra27
Status: new
Resolution: open
Priority: normal
Severity: feature
Category: standard library

Bug description

Currently %! is a no-op for functions which aren't writing to buffered channels. I'm wondering what it might be to have ksprintf f "foo%!bar" result in f "foo"; f "bar".

Additional information

Obviously, this would have to be done with a new function, as it would be a change of semantics for Printf.ksprintf.

@vicuna
Copy link
Author

vicuna commented Mar 19, 2018

Comment author: @Octachron

Would it not be better to merge the intermediaries result with f "foo" "bar" rather than constraining the continuation to return unit?

@vicuna
Copy link
Author

vicuna commented Mar 28, 2018

Comment author: @diml

What would be the use case for such a feature?

@github-actions
Copy link

github-actions bot commented May 7, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 7, 2020
@dra27
Copy link
Member

dra27 commented May 7, 2020

IIRC it was a halfway house for translating VT100 sequences to Windows API calls which I was doing - if you can effectively separate the calls on %! then you can correctly translate and print "foo\n%!bar\n" (flush "foo"to output, buffer"bar") and "foo\n%!bar\n%!"` (print both lines at once)

@dra27 dra27 removed the Stale label May 7, 2020
@Drup
Copy link
Contributor

Drup commented May 7, 2020

It is a rather important property of Format/Printf that the continuation is called once at the end. If you want to call a function on each string, it seems better to make your own formatter. I suggest we close.

@dra27
Copy link
Member

dra27 commented May 7, 2020

@Drup - how so?

@Drup
Copy link
Contributor

Drup commented May 7, 2020

Format.formatter_of_out_functions allows you to create a formatter where you provides the function called on each substrings. That's the proper (and intended) way to use printf on semi-exotic channels.

@dra27
Copy link
Member

dra27 commented May 7, 2020

What I was asking was the "important property" you refer to - what prevents there being a version of Printf.ksprintf which behaves as I describe? (but thanks for the pointer - in the wood for the trees, I hadn't considered using formatter_of_out_functions to solve this - one ends up in Format at surprising times, sometimes)

@jberdine
Copy link
Contributor

jberdine commented May 7, 2020

The manual for kfprintf says: passes the formatter to its first argument at the end of printing. I think it is implicit that the continuation is called only when mentioned, but could be wrong. So to my understanding, that means that invoking the continuation at other times is a serious change in semantics. It would certainly break various aspects of my code.

@dra27
Copy link
Member

dra27 commented May 8, 2020

“Obviously, this would have to be done with a new function, as it would be a change of semantics for Printf.ksprintf.”! I was curious that @Drup refers to the entire module...

@lpw25
Copy link
Contributor

lpw25 commented May 8, 2020

(@dra27 If you are proposing a new function then maybe you should change the title)

@jberdine
Copy link
Contributor

jberdine commented May 8, 2020

+1 And I would suggest not naming the new function k*printf to avoid the significantly different interpretations of the k prefix.

@dra27 dra27 closed this as completed Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants