tj / luna

luna programming language - a small, elegant VM implemented in C
2.45k stars 147 forks source link

interpolation #34

Open tj opened 11 years ago

tj commented 11 years ago

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 %

z0w0 commented 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)
tj commented 11 years ago

yeah sprintf style is usually just fine, though expanding interpolation to concatenation is more efficient for the simple substitutions

DAddYE commented 11 years ago

Im for:

'$ %.2f' % 1.2
'%one% key' % a
'%s %d' % ['a', 1]
DAddYE commented 11 years ago

I like also fmt() but with stdout puts ? stdout puts fmt('fooo %s', 'bar') ?

tj commented 11 years ago

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