Perhaps even the other way around may be better to keep things as similar
as possible to the regular println syntax:
$(arg, fmt)
v0 = 1.234
v1 = 200
@print ("some formatted numbers: $(v0, 0.2f), $(v1, 06d)")
On Friday, June 13, 2014 10:56:35 AM UTC+8, Andrew Simper wrote:
>
> I love the old style c formatting specifiers, they are quick and easy to
> use. I noticed that there is an @printf macro that will still have the same
> sort of issues as the old c version in that you have to match the order of
> vargs to that of the formating string which can lead to errors. I noticed
> that the println function uses $(var) syntax like php which I think is much
> better since the variable is inplace in the string.
>
> What do people think about keeping the same php type syntax but adding an
> optional formatting element and making the $(arg) into a tuple $(fmt, arg)
> so you can't screw up the matching of the format with the argument?
>
> so using this type of style:
> v0 = 1.234
> v1 = 200
> @print ("some formatted numbers: $(0.2f, v0), $(06d, v1)")
>
>
> instead of the current:
> @printf("some formatted numbers: %0.2f, %06d", v0, v1)
>
>
> both output:
>
> *some formatted numbers: float 1.23, int 000200*
>
>
>
>