Re: [julia-users] Re: Create formatted string

2015-03-10 Thread Tony Fong
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,

Re: [julia-users] Re: Create formatted string

2015-03-10 Thread Dominique Orban
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

Re: [julia-users] Re: Create formatted string

2014-04-16 Thread Dominique Orban
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Jeff Waller
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Jameson Nash
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Stefan Karpinski
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 vtjn...@gmail.com wrote: I would pick (4): sprintf should be modified to deal with it. My

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Jeff Waller
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Stefan Karpinski
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Jeff Waller
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

Re: [julia-users] Re: Create formatted string

2014-04-14 Thread Tony Kelman
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 a

[julia-users] Re: Create formatted string

2014-04-13 Thread Jeff Waller
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

Re: [julia-users] Re: Create formatted string

2014-04-13 Thread John Myles White
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)

Re: [julia-users] Re: Create formatted string

2014-04-13 Thread Dominique Orban
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

Re: [julia-users] Re: Create formatted string

2014-04-13 Thread Mike Innes
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:

Re: [julia-users] Re: Create formatted string

2014-04-13 Thread Stefan Karpinski
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+00