Open tj opened 11 years ago
What about a string formatting function (or macro) like Rust? I think it works pretty nicely.
bar = "bar"
fmt("foo %s", bar)
yeah sprintf style is usually just fine, though expanding interpolation to concatenation is more efficient for the simple substitutions
Im for:
'$ %.2f' % 1.2
'%one% key' % a
'%s %d' % ['a', 1]
I like also fmt()
but with stdout puts
? stdout puts fmt('fooo %s', 'bar')
?
with the way methods are parsed now it would allow for "hello %s".format("world")
which is equivalent to format("hello %s", "world")
, a canonical %
would be nice, I definitely like that in python but is definitely a tacked on thing. Or julia-style and treat that as %("hello %s", "world")
where %
is user-defined. I have mixed feelings about operator overloading though
not a huge fan of ruby-style
foo #{bar}
etc, if you have complex expressions you might as well use concatenation, and for smaller simple expressions it's noisy. I'd rather do some simpler substitution or perhaps python style%