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 4 commits into from Aug 15, 2019


Copy link

commented Aug 15, 2019

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.

a2800276 added 4 commits Aug 15, 2019
ry approved these changes Aug 15, 2019
Copy link

left a comment

Beautiful, thanks Tim :)


@ry ry merged commit f7b5116 into denoland:master Aug 15, 2019

5 checks passed

denoland.deno_std Build #20190815.8 succeeded
denoland.deno_std (Linux) Linux succeeded
denoland.deno_std (Mac) Mac succeeded
denoland.deno_std (Windows) Windows succeeded
license/cla Contributor License Agreement is signed.

This comment has been minimized.

Copy link

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.


This comment has been minimized.

Copy link
Contributor Author

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:


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:




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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.