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

Add printf function #731

Closed
adamperlin opened this issue Jul 3, 2018 · 4 comments
Closed

Add printf function #731

adamperlin opened this issue Jul 3, 2018 · 4 comments

Comments

@adamperlin
Copy link
Contributor

From ifql created by nathanielc : influxdata/ifql#316

Possible function signature printf = (fmt, args={}) => ... where fmt is the format string and args is an object of values to format.

@mark-rushakoff mark-rushakoff transferred this issue from another repository Jan 8, 2019
@affo
Copy link
Contributor

affo commented Jun 13, 2019

The problem in directly porting Go's fmt.Print is that we don't support variadic arguments, neither mixed-type arrays. We could support something like:

import s "strings"
s.fmt("this is a number {n}, this is a string {s}", o: {n: 1, s: "lol"})

I don't like the idea of printf, but I like strings.fmt. If one wants to print to screen, he can simply write down the expression as we did up to now, as we suppose that the output of an ExpressionStatment is the screen (if the query is sent to a server, then what is printed to screen is not returned).

@russorat russorat added enhancement New feature or request new function labels Mar 4, 2020
@quentinmit
Copy link

I just ran across this issue while trying to format a date. While you probably also need a date-specific format function, how would you feel about at least defining the simpler function of

number.sprintf(fmt:"%02x", v: 5)

to allow sprintf'ing a single number? Or even just sprintf with a single-type array would still be super useful (though harder to justify, I think). While sprintf can also be used on strings, I feel like 90% of the use cases would be covered by sprintf on numbers.

The problem with the s.fmt proposed above is that it has no mechanism for using any of the sprintf-style format operators. And I don't think you really want to be in the business of inventing your own format string syntax. I wonder if it's possible to write a parser that takes a Python-style format string (e.g. this is a number %(n)02x, this is a string %(s)s) and translates it into a series of calls to fmt.Sprintf.

Copy link

This issue has had no recent activity and will be closed soon.

@quentinmit
Copy link

This hasn't been completed and is still needed

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