Hi Tom

Sorry to take so long to get back to you, I had to go away for a couple of
days. Thanks for the installation information, @fmt is working fine now.
It's still not as useful as the Fortran print * formatting however because
it ​requires the user to know what's coming. For example, the Fortran code

x = -2.34e-12
do i = 1, 5
  x = -x*5000.
  print *, i, x
end do

produces

1     1.170000E-08
2    -5.850000E-05
3     0.292500
4     -1462.5
5     7.312501e+06

As you can see, print * figured out when exponential notation is necessary
and automatically used it.

I'm retired now, but when I was working I spent a lot of time writing
numerical analysis programs for various engineering issues (elastic
material deformation, electron trajectories, etc.) While a  program was
being developed I didn't care about the aesthetics of my printout, I just
needed useful information - and early on, numerical or algebraic or
programming errors could easily produce results off by 10 order of
magnitude!

I think a capability such as this in Julia would be heavily used. I wish I
had the expertise to write it.

Larry



On Tue, Sep 22, 2015 at 4:59 PM, Tom Breloff <t...@breloff.com> wrote:

> Sorry I wasn't expecting you to run it... just comment.  You'll have to do:
>
> Pkg.rm("Formatting")
> Pkg.clone("https://github.com/tbreloff/Formatting.jl.git";)
> Pkg.checkout("Formatting", "tom-fmt")
>
> Let me know if that works.
>
> On Tue, Sep 22, 2015 at 5:52 PM, lawrence dworsky <
> m...@lawrencedworsky.com> wrote:
>
>> I'm afraid my beginner status with Julia is showing:
>>
>> I ran Pkg.add("Formatting"), and then   using Formatting   came back with
>> a whole bunch of warnings, most about  Union(args...) being depricated, use
>> Union(args....) instead.
>>
>> When all is said and done,   fmt_default!  gives me a  UndefVarError.
>>
>> Help!
>>
>>
>>
>> On Tue, Sep 22, 2015 at 2:45 PM, Tom Breloff <t...@breloff.com> wrote:
>>
>>> 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> 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> 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