Thanks Larry, that's helpful.  Just for discussions sake, here's a quick 
macro that calls my proposed `fmt` method under the hood, and does 
something similar to what you showed.  What do you think about this style 
(and what would you do differently)?
 
using Formatting

macro fmt(args...)
 expr = Expr(:block)
 expr.args = [:(print(fmt($(esc(arg))), "\t\t")) for arg in args]
 push!(expr.args, :(println()))
 expr
end


And then an example usage:

In:

x = 1010101
y = 555555.555555555
fmt_default!(width=15)

@fmt x y

fmt_default!(Int, :commas)
fmt_default!(Float64, prec=2)

@fmt x y


Out:

        1010101  555555.555556 
      1,010,101      555555.56



On Tuesday, September 22, 2015 at 3:08:35 PM UTC-4, lawrence dworsky wrote:
>
> Hi Tom
>
> What I like about it is that you can just use print *, dumbly and it 
> always provides useful, albeit not beautiful, results. When I'm writing a 
> program, I use print statements very liberally to observe what's going on - 
> I find this more convenient than an in-line debugger. 
>
> As the last line in my program below shows, it's easy to switch to 
> formatted output when you want to. The formatting capability is pretty 
> thorough, I'm just showing a simple example.
>
> This Fortran program doesn't do anything, it just illustrates what the 
> print statement produces:
>
>
> real x, y
> integer i, j
> complex z
> character*6  name
>
> x = 2.6
> y = -4.
> i = 36
> j = -40
> z = cmplx(17., 19.)
> name = 'Larry'
>
> print *, x, y, i, j, z
> print *, 'x = ', x, ' and j = ', j
> print *, 'Hello, ', name, j
> print '(2f8.3, i5)', x, y, j
>
> stop
> end
>
>
> The output is:
>
>         2.60000             -4.00000                   36             -40 
>  (17.0000, 19.0000)
> x =         2.60000       and j =                -40
> Hello, Larry                 -40
>   2.600   -4.000  -40
>
>
> Is this what you are looking for?
>
> Larry
>
>
>
> On Tue, Sep 22, 2015 at 11:57 AM, Tom Breloff <t...@breloff.com 
> <javascript:>> wrote:
>
>> Larry: can you provide details on exactly what you like about Fortran's 
>> print statement?  Did it provide good defaults?  Was it easy to customize?
>>
>> On Tue, Sep 22, 2015 at 12:55 PM, LarryD <larryd...@gmail.com 
>> <javascript:>> wrote:
>>
>>> Something I miss from Fortran is the very convenient default "print *, 
>>> ..... "  It handled almost 100% of my needs while working on a program and 
>>> was easily replaced by real formatting when the time came. Is there any 
>>> chance that Julia could get something like this?
>>>
>>> Thanks
>>>
>>>
>>> On Monday, September 21, 2015 at 3:46:31 AM UTC-5, Ferran Mazzanti wrote:
>>>>
>>>> Dear all,
>>>>
>>>> I could use some help here, because I can't believe I'm not able to 
>>>> easily print formatted numbers under Julia in a easy way. What I try to do 
>>>> is to write a function that, given a vector, prints all its components 
>>>> with 
>>>> a user-defined format. I was trying something of the form
>>>>
>>>> function Print_Vec(aux_VEC,form_VEC)
>>>>     form_VEC :: ASCIIString
>>>>     str_VEC  = "%16.8f"
>>>>     for elem_VEC in aux_VEC
>>>>         str_VEC += @sprintf(form_VEC,elem_VEC)
>>>>     end
>>>>     return str_VEC
>>>> end
>>>>
>>>> However, that doesn't work because it looks like the first argument in 
>>>> @sprintf must be a explicit string, and not a variable.
>>>> Is there anything I can do with that?
>>>>
>>>> Thanks a lot for your help.
>>>>
>>>
>>
>

Reply via email to