To clarify, I meant something like

function printnums(x,y,z)
  @sprintf("%.2f %.2f %.2f", x, y, z)
end

Which will both be type safe and have good performance. It doesn't solve
all the issues, but as I said, it does solve the specific issue of
repetition of format strings.

On 4 December 2014 at 13:49, Ivar Nesje <iva...@gmail.com> 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.
>
> kl. 13:49:09 UTC+1 torsdag 4. desember 2014 skrev Mike Innes følgende:
>>
>> I'm not sure I understand – C's sprintf certainly has problems with type
>> safety, but a function wrapping Julia's @sprintf can't *not* be strongly
>> typed. No?
>>
>> On 3 December 2014 at 23:43, <ele...@gmail.com> wrote:
>>
>>>
>>> As Stefan said above, the problem with traditional (s)printf functions
>>> is type safety.
>>>
>>> On Thursday, December 4, 2014 4:53:17 AM UTC+10, Mike Innes wrote:
>>>>
>>>> #9423 <https://github.com/JuliaLang/julia/pull/9243> should help with
>>>> the repetition of format strings issue. It occurs to me now that you can
>>>> always just write a function wrapper for `@sprintf` to solve that issue but
>>>> this might still be useful.
>>>>
>>>> [...]
>>>
>>
>>

Reply via email to