The trouble is that what's inside the parentheses is just an expression and
printf format specifiers are not generally valid expressions. I've been
meaning for a while to take a crack at making some of the printf formatting
machinery a little more generally usable. It's easier now that Jameson,
Keno and Jeff have made it efficient enough to use local variables for the
printf machinery instead of having to use const globals.


On Thu, Jun 12, 2014 at 11:05 PM, Andrew Simper <[email protected]>
wrote:

> 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*
>>
>>
>>
>>

Reply via email to