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. On Thu, Dec 4, 2014 at 9:24 AM, Tony Fong <tony.hf.f...@gmail.com> 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. >> >