I’d urge you to reconsider your usage of whitespace. There’s useful points made here (https://github.com/JuliaLang/julia/issues/7232) about the problems raised by f (a, b) as a stylistic habit, especially regarding the fact that writing [f (x)] when you meant [f(x)] will give you the wrong answer.
— John On Jul 30, 2014, at 8:30 AM, Neal Becker <[email protected]> wrote: > Thanks! Here's my working version: > type FIR{in_t, coef_t} > in::Vector{in_t} > coef::Vector{coef_t} > function FIR (in::Vector{in_t}, coef::Vector{coef_t}) > new (zeros (in_t, size (in)), copy (coef)) > end > end > > FIR{in_t, coef_t} (in::Vector{in_t}, coef::Vector{coef_t}) = FIR{in_t, coef_t} > (in, coef) > > w = zeros (Float64, 10) > g = FIR{Float64,Float64} (w,w) > f = FIR(w,w) > > > I'm surprised (shocked) by the comment about whitespace after the name of the > function. I may find it hard to love a language where the addition of > whitespace produces ambiguity. (Not to mention, I always put whitespace > between > name of function and args) > > John Myles White wrote: > >> Hi Neal, >> >> I think rewriting your code to follow a little bit more conventional Julia >> style will help you to see where you’ve gone wrong: >> >> type FIR{S, T} >> in::Vector{S} >> coef::Vector{T} >> function FIR(in::Vector{S}, coef::Vector{T}) >> new(zeros(S, size(in)), coef) >> end >> end >> >> FIR{S, T}(in::Vector{S}, coef::Vector{T}) = FIR{S, T}(zeros(S, size(in)), >> coef) >> >> w = zeros(Float64, 10) >> f = FIR(w,w) >> >> Note that you must include the outer constructor definition or you will not >> have access to the custom inner constructor that you’ve defined. This is one >> of the unusual properties of how parametric types work. >> >> Also worth noting that, because of ambiguities, Julia may one day need to >> prohibit function invocation with spaces between function names and >> parentheses. So it’s better to write FIR(a, b) than to write FIR (a, b). >> >> — John >> >> On Jul 30, 2014, at 8:00 AM, Neal Becker >> <[email protected]> wrote: >> >>> As a learning exercise, I am trying to code a simple FIR filter. >>> As a start, it has 2 fields and a constructor: >>> >>> type FIR{in_t, coef_t} >>> in::Vector{in_t} >>> coef::Vector{coef_t} >>> FIR (in_::Vector{in_t}, coef_::Vector{coef_t}) = (x=new(); x.in = >>> zeros(in_t, size (in_)); x.coef = coef_;) >>> end >>> >>> w = zeros (Float64, 10) >>> f = FIR{Float64,Float64}(w,w) >>> >>> This code executes, but seems very confused: >>> julia> typeof(f) >>> Array{Float64,1} >>> >>> Huh? I expected "f" to be of type FIR{Float64,Float64}. Clearly I'm doing >>> something very wrong. >>> > >
