On Thu, 2016-04-07 at 21:27, Lucas de Almeida Carotta <fazendafi...@gmail.com> 
wrote:
> How I make this code works?
>
> function read_matrix( data::DataType=Any, spacing=" " )
>     local line::Vector{ data } = Array( data, 1 )
>     local matrix::Matix{ data } = Array( Array{ data, 1 }, 1 )
>
>     while !eof( STDIN )
>         line = [ parse( data, i ) for i in split( chomp( readline( STDIN )
> ), spacing ) ]
>         push!( matrix, line )
>     end
>
>     return matrix
> end

Note that the `local` is not necessary (it does nothing) as assignment
creates a local variable.  Also, the type-declaration is unnecessary.
Assuming it is a matrix, i.e. all lines are the same length.  Untested
code:

function read_matrix( T::DataType=Any, spacing=" " )
    out = T[] # equivalent to Array(T,1)

    nlines = 0
    while !eof( STDIN )
        # note you can only push to 1-D arrays
        push!(out, [ parse( data, i ) for i in split( chomp( readline( STDIN ) 
), spacing ) ] )
        nlines += 1
    end

    return reshape(out, nlines, div(length(out),nlines))  # maybe needs a 
transpose
end

Reply via email to