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

sprintf implementation / golang fmt. #566

Merged
merged 4 commits into from
Aug 15, 2019
Merged

sprintf implementation / golang fmt. #566

merged 4 commits into from
Aug 15, 2019

Conversation

a2800276
Copy link
Contributor

I've attached code for an sprintf implementation that is (loosely) based on the golang fmt package. I've been told there may be some interest to include it to std.

[I created a post request a couple of hours ago but was not aware of all the linter CI going on, sorry about that.]

It's still in and early form, but fairly full featured.

A number of semantic issues are still unclear to me, mostly concerning what the default representation of arbitray objects should be, what flags/variants would be useful, etc. I've outlined a number of those issues in the README and would be interested in receiving input into those points as well.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, thanks Tim :)

LGTM

@ry ry merged commit f7b5116 into denoland:master Aug 15, 2019
@j-f1
Copy link

j-f1 commented Aug 21, 2019

A useful feature that Python’s format strings have is the ability to pass an object to the format function instead of a list of values. You can use %(key)s in the string to pull keys off the object.

@a2800276
Copy link
Contributor Author

a2800276 commented Aug 23, 2019

I like the idea and have thought about it previously, I'm not sure what the implementation would look like. Currenlty, positional params are indicated with:

%[<index>]s

where <index> refers to the index'th paramter. Sematics of the sprintf function implies that there are a number of different parameters. To reference keys, it becomes necessary to indicate the parameter passed to sprintf and additionally the key or index of the value within the parameter, i.e:

 %[<index>][<key>]s

or

%[<index>.<key>]s

Alternatively, the based value selection could imply only passing a single parameter. This has different sematics of a printf depending on how it's called as a consequence, and I find that fairly unpleasing.

OR there could be a different formatting function for this entirely.

I'd be super happy to hear your thoughts on what the interface / format string syntax for this could look like, because I can't really think of anything reasonable myself.

What I would like to avoid is straying from existing semantics of printf entirely, the function should be able to perform "normal" formatting tasks in the way someone acquainted with posix would expect.

ry pushed a commit to ry/deno that referenced this pull request Oct 9, 2019
inverted-capital pushed a commit to dreamcatcher-tech/napps that referenced this pull request Oct 24, 2024
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

Successfully merging this pull request may close these issues.

3 participants