Yes, you can directly use the formatting string as the first argument.
Just that if the same formatting string is repeatedly used, it is more
efficient to first compile it into an instance of FormatExpr and use this
instance instead.
Best,
Dahua
On Wednesday, February 26, 2014 9:39:01 AM UTC-
But anyway It doesn't seem to be needed?:
julia> format_string = "{1} + {2} = {3}\n"
"{1} + {2} = {3}"
julia> format_expr = f"{1} + {2} = {3}\n"
You mean like this, am I right? I like this package!
julia> using Formatting
julia> macro f_str(e)
:(FormatExpr($e))
end
julia> a = 7; b = 5; c = 3;
julia> printfmt(f"({1}*{2}) / {3} = {4}", a, b, c, (a*b)/c)
(7*5) / 3 = 11.666
On Tuesday, 25 February 2014 22:23
Andrew,
Thanks for your interest. Currently, the most efficient way is to first
construct an instance of FormatExpr and applies it repeatedly.
The original motivation was to provide a run-time counter part of @printf
and friends. It doesn't support macros at this point, but may consider
adding
oh, also, i always assumed that @printf was a macro so that it could do
this compilation at compile time. have you considered implementing a macro
that is similarly efficient? then someone could write
@printfmt("...", ...")
and still (i guess) have things precompiled.
andrew
On Tuesday
this looks nice, but i have some questions :o)
first, if i want efficient printing, is
printfmt(FormatExpr(""), ...)
sufficient? does the compiler lift the FormatExpr into a constant? or do
i need to b more explicit. something like
const fmt = FormatExpr("...") # top level