I'm trying to learn macros. Can you help me to get this working? Currently 
the error is that arr is not defined. Probably an obvious mistake, but I 
just don't get hang of it. 

macro Write(arr)
    @eval begin
        for i in arr
         @sprintf("%12.6f\n",i)
        end
    end
end


a = 1e5*rand(10)
@Write a



On Tuesday, July 14, 2015 at 4:20:43 PM UTC+3, [email protected] wrote:
>
> You could just use a macro to take the format and the array and let it 
> write the "messy" loop for you.
>
> On Tuesday, July 14, 2015 at 8:39:44 PM UTC+10, Ferran Mazzanti wrote:
>>
>> Yes thanks, I knew already looped solutions :)
>> I was looking for somethin' compact as in the fortran statement above, 
>> though. It makes things more *neat*, if there's any such thing.
>>
>> On Tuesday, July 14, 2015 at 12:08:59 PM UTC+2, Kaj Wiik wrote:
>>>
>>> Would this work for you:
>>> julia> a = 1e5*rand(1000)
>>> julia> for i in a
>>>        @printf("%12.6f\n", i)
>>>        end
>>> 74708.038385
>>> 71244.774457
>>>  5057.229038
>>>  3761.297034
>>> ...
>>>
>>> Remember that loops are fast in Julia...
>>>
>>> Kaj
>>>
>>>
>>>
>>> On Tuesday, July 14, 2015 at 9:14:37 AM UTC+3, Ferran Mazzanti wrote:
>>>>
>>>> Thanks for the info. Actually my question comes from old fortran style, 
>>>> where I can write something of the form
>>>> Write(1,'1000f12.6') a
>>>> where a is an array. The string inside the write function says I can 
>>>> print 1000 doubkes in 12 characters with 6 decimals. So the string is a 
>>>> constant literal, and array a can contain 1000 or less elements that will 
>>>> be properly formatted. Is there a way to do something like this in Julia?
>>>> What if Inwant to print 1000 float64 on the same line with a given 
>>>> format for each element?
>>>> Maybebthis is easier...
>>>> Best regards and thanks.
>>>> Ferran.
>>>
>>>

Reply via email to