abs icon indicating copy to clipboard operation
abs copied to clipboard

Make fmt() function more like C's sprintf()

Open gromgit opened this issue 5 years ago • 1 comments

At least reduce the number of cases for Go's dreaded %!d(string=5) to appear when the user applies printf format tags, as shown in https://github.com/abs-lang/abs/issues/374#issuecomment-669694631

gromgit avatar Aug 06 '20 09:08 gromgit

This PR now swings in the other direction: %s only works properly with strings. The easy fix, if %s really means "print the canonical representation of whatever it's pointing at", is to replace all %s with %v in evaluator.fmtFn() before calling fmt.Sprintf().

Alternatively, the fmt() portion of https://www.abs-lang.org/types/string could point at https://golang.org/pkg/fmt/#hdr-Printing instead of the current https://linux.die.net/man/3/sprintf, and existing examples be updated to use %v for this purpose instead of %s.

What do you think?

gromgit avatar Aug 06 '20 10:08 gromgit