On Friday, December 5, 2014 12:39:13 AM UTC+10, Stefan Karpinski wrote:
>
> One way of doing this would be to generate named functions that do a 
> particular formatting, e.g. when someone does printf("%5.2d %-s %73f\n", 
> ...) do
>
> @eval function $(symbol("__printf__%5.2d %-s %73f\n"))(arg1, arg2, arg3)
>     # generate code here
> end
>
>
> Then call that function. That uses the module as a lookup table. 
> Unfortunately, there's still overhead to lookup the function – using a hash 
> table might be more efficient anyway. Honestly, the whole printf way of 
> doing formatting is kind of a horrid hack and should probably be replaced 
> with something saner.
>

And extensible to user types.  But probably not C++'s << system.

Cheers
Lex
 

>
> On Thu, Dec 4, 2014 at 9:24 AM, Tony Fong <tony.h...@gmail.com 
> <javascript:>> wrote:
>
>> That's exactly the approach in the c-style portion of Formatting.jl.
>>
>> On Thursday, December 4, 2014 8:49:15 PM UTC+7, Ivar Nesje wrote:
>>>
>>> A function wrapping Julia @sprintf will be typesafe, but will have 
>>> terrible performance. One could cache the generated functions though, so 
>>> that the format string will only be used as a lookup in a hash table that 
>>> points to the specialized (typesafe) function for that format string.
>>>
>>
>

Reply via email to