Re: [julia-users] Create formatted string

2014-11-21 Thread Tony Fong
For formatting just one number into a string (instead of multi-arg sprintf) you can use sprintf1 in https://github.com/tonyhffong/NumFormat.jl. It's somewhat close to standard macro speed. On Friday, April 18, 2014 12:58:08 AM UTC+7, Dominique Orban wrote: Here are some timings comparing

Re: [julia-users] Create formatted string

2014-04-17 Thread John Myles White
I think the question is how to time a proposed sprintf() function vs. the existing @sprintf macro. -- John On Apr 17, 2014, at 7:27 AM, Stefan Karpinski ste...@karpinski.org wrote: I'm not sure what you mean, but doing things in a loop and timing it is the normal way. The lack of

Re: [julia-users] Create formatted string

2014-04-17 Thread Dominique Orban
Here are some timings comparing @printf with the proposed @eval option. I also wanted to try a variant that calls libc's printf directly. I came up with this implementation: https://gist.github.com/11000433. Its advantage is that you can print an array's address using %p (for what it's worth).

Re: [julia-users] Create formatted string

2014-04-13 Thread Stefan Karpinski
Note that to match the functionality of our @printf macro, it has to handle different types of arguments correctly, which is non-trivial. Not saying it's impossible, but it isn't easy. On Sat, Apr 12, 2014 at 6:08 PM, Kevin Squire kevin.squ...@gmail.comwrote: I have a port of a BSD printf

[julia-users] Create formatted string

2014-04-12 Thread Dominique Orban
Sorry if this is a RTFM, but I can't find the answer in the documentation or on the web. I may have missed it. I come from Python where I can build strings with formatted data using a syntax like s = pi=%7.1e % acos(-1) How do I accomplish that in Julia? @printf doesn't do the job because it

Re: [julia-users] Create formatted string

2014-04-12 Thread John Myles White
@sprintf On Apr 11, 2014, at 11:18 PM, Dominique Orban dominique.or...@gmail.com wrote: Sorry if this is a RTFM, but I can't find the answer in the documentation or on the web. I may have missed it. I come from Python where I can build strings with formatted data using a syntax like s =

Re: [julia-users] Create formatted string

2014-04-12 Thread Dominique Orban
Thank you! Such a basic operation could feature a bit more prominently in the documentation. On Friday, April 11, 2014 11:21:28 PM UTC-7, John Myles White wrote: @sprintf On Apr 11, 2014, at 11:18 PM, Dominique Orban dominiq...@gmail.comjavascript: wrote: Sorry if this is a RTFM, but

Re: [julia-users] Create formatted string

2014-04-12 Thread Dominique Orban
As a follow-up question, why is the following not allowed? julia fmt = %8.1e; julia @sprintf(fmt, 3.1415) ERROR: first or second argument must be a format string I don't see how it's different from julia @sprintf(%8.1e, 3.1415) What's the appropriate syntax? Thanks. On Friday, April 11,

Re: [julia-users] Create formatted string

2014-04-12 Thread John Myles White
@sprintf is a macro, not a function. It doesn't evaluate its inputs: it just rewrites the inputs into something else (usually less readable) that carries out the actual computation. You can see what it does using the macroexpand function: julia macroexpand(quote @sprintf(%8.1e, 3.1415) end)

Re: [julia-users] Create formatted string

2014-04-12 Thread Mike Innes
That @sprintf is a macro sort of explains why using a run-time value doesn't work in the same way, but it isn't really *the* reason since @sprintf(fmt, val) could work in principle – it would just have to delegate to a function if its argument isn't a compile-time string. If using a run-time

Re: [julia-users] Create formatted string

2014-04-12 Thread Milan Bouchet-Valat
Le samedi 12 avril 2014 à 04:11 -0700, Mike Innes a écrit : That @sprintf is a macro sort of explains why using a run-time value doesn't work in the same way, but it isn't really the reason since @sprintf(fmt, val) could work in principle – it would just have to delegate to a function if its

[julia-users] Create formatted string

2014-04-12 Thread Kevin Squire
I have a port of a BSD printf function which works at about half the speed of the @printf macro. I was hoping to make it more functional/less ugly, but I'll see if I can't get it into a pull request, at least, or in a package if it's not accepted. I'll also point out Dahua's Formatting.jl