Likewise I am having problems with @sprintf
Is this because @sprinf is macro? The shorthand of expanding a printf with
format the contents of an array is desirable. I would have expected the
... operator to take an array of length 2 and turn it into 2 arguments.
julia> X=[1 2]
1x2
As far as the macro is concerned, the splat isn’t executed: it’s just
additional syntax that gets taken in as a whole expression.
The contrast between how a function with splatting works and how a macro with
splatting works might be helpful:
julia> function splat(a, b...)
println(a)
So what's the preferred Julia syntax to achieve what I meant here:
julia> fmt = "%8.1e";
julia> @sprintf(fmt, 3.1415)
ERROR: first or second argument must be a format string
On Sunday, April 13, 2014 1:31:57 PM UTC-7, John Myles White wrote:
>
> As far as the macro is concerned, the splat isn’t
It occurs to me that, if you really need this, you can define
sprintf(args...) = eval(:@sprintf($(args...)))
It's not pretty or ideal in terms of performance, but it will do the job.
fmt = "%8.1e"
sprintf(fmt, 3.141) #=> " 3.1e+00"
On Sunday, 13 April 2014 22:47:12 UTC+1, Dominique Orban wrote:
Please don't do this – or if you do and your program is amazingly slow,
then consider yourself warned. You can define a custom formatting function
pretty easily:
julia> fmt = "%8.1e"
"%8.1e"
julia> @eval dofmt(x) = @sprintf($fmt, x)
dofmt (generic function with 1 method)
julia> dofmt(1)
" 1.0e+0
That's pretty cool, but I have a followup.
Does this mean
1) Writing macros is implicitly harder because they don't deal with
(splatted) collections as easy as functions?
2) This is not really important because it hardly is ever done?
3) sprintf should be re-written as a function?
4) sprintf shou
I would pick (4): sprintf should be modified to deal with it.
My reason: sprintf knows how many arguments it is expecting, so if it
sees a `...` on the last argument, it could easily emit code to
extract the elements that it needs
Also (1) / (2): splatting arguments is something that happens in
Up for grabs issue: https://github.com/JuliaLang/julia/issues/6520. If
anyone is interested in doing a bit of metaprogramming, this is a good
opportunity.
On Mon, Apr 14, 2014 at 2:47 AM, Jameson Nash wrote:
> I would pick (4): sprintf should be modified to deal with it.
>
> My reason: sprintf
On Monday, April 14, 2014 10:58:15 AM UTC-4, Stefan Karpinski wrote:
>
> Up for grabs issue: https://github.com/JuliaLang/julia/issues/6520. If
> anyone is interested in doing a bit of metaprogramming, this is a good
> opportunity.
>
Oh! Me, I mean I'm saying all these things, I should also i
The macros are defined here:
https://github.com/JuliaLang/julia/blob/master/base/printf.jl#L750-L784
It should be a matter of detecting that there's a splat happening – keep in
mind that splats can be mixed with other arguments – and emitting the
appropriate code in the macro. It may be possible
On Monday, April 14, 2014 11:36:40 AM UTC-4, Stefan Karpinski wrote:
>
> The macros are defined here:
>
> https://github.com/JuliaLang/julia/blob/master/base/printf.jl#L750-L784
>
>
Do I need to git the most up-to-date source for Julia as well and make a
language development environment? What's
You can work from a binary installation to test your changes locally, but
you'll need to rebuild the "system image" for changes to Julia code in base
to take effect. Last I checked this detail is not explicitly documented
anywhere, adding a sentence or two to CONTRIBUTING.md about this would be
How would one go about benchmarking a set of implementations like those?
On Sunday, April 13, 2014 3:22:58 PM UTC-7, Stefan Karpinski wrote:
>
> Please don't do this – or if you do and your program is amazingly slow,
> then consider yourself warned. You can define a custom formatting function
>
I'm not sure what you mean, but doing things in a loop and timing it is the
normal way. The lack of usefulness of my answer may be indicative that I
don't understand the question.
On Wed, Apr 16, 2014 at 11:13 PM, Dominique Orban wrote:
> How would one go about benchmarking a set of implementat
This is an old question about computed format strings, but it's still
biting me. I've been following your suggestion and I defined
print_formatted(fmt, args...) = @eval @printf($fmt, $(args...))
Now I am in a situation where fmt is computed inside a function, and my
function executes in roughly
Try Formatting.jl? (https://github.com/lindahua/Formatting.jl)
On Wednesday, March 11, 2015 at 7:16:55 AM UTC+7, Dominique Orban wrote:
>
> This is an old question about computed format strings, but it's still
> biting me. I've been following your suggestion and I defined
>
> print_formatted(fmt,
16 matches
Mail list logo