# Base.call() in Julia 0.6

**URL:** https://discourse.julialang.org/t/base-call-in-julia-0-6/3983
**Category:** General Usage
**Created:** [May 30, 2017, 4:34am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983 "2017-05-30T04:34:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![charlesll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charlesll/32/3255_2.png) [@charlesll](https://discourse.julialang.org/u/charlesll)
#### Post date: [May 30, 2017, 4:34am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/1 "2017-05-30T04:34:44Z")

</div>

Hi All,

I can’t find information about the usage of base.call in Julia 0.6, but it breaks some code I have and that works well in Julia 0.5…

The function I am trying to run is

```julia
immutable SavitzkyGolayFilter{M,N} end

@generated function Base.call{M,N,T}(::Type{SavitzkyGolayFilter{M,N}},
     data::AbstractVector{T})

     #Create Jacobian matrix
     J = zeros(2M+1, N+1)
     for i=1:2M+1, j=1:N+1
         J[i, j] = (i-M-1)^(j-1)
     end
     e₁ = zeros(N+1) 
     e₁[1] = 1.0
    
     #Compute filter coefficients
     C = J' \ e₁

     #Evaluate filter on data matrix

     To = typeof(C[1] * one(T)) #Calculate type of output
     expr = quote
         n = size(data, 1)
         smoothed = zeros($To, n)
         @inbounds for i in eachindex(smoothed)
             smoothed[i] += $(C[M+1])*data[i]
         end
         smoothed
     end

     for j=1:M
         insert!(expr.args[6].args[2].args[2].args, 1,
             :(if i - $j ≥ 1
                 smoothed[i] += $(C[M+1-j])*data[i-$j]
               end)
         )
         push!(expr.args[6].args[2].args[2].args,
             :(if i + $j ≤ n
                 smoothed[i] += $(C[M+1+j])*data[i+$j]
               end)
         )
     end

     return expr
end

```

And it returns a

`LoadError: UndefVarError: call not defined`

in Julia 0.6. I think I have missed something there ?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 30, 2017, 4:57am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/2 "2017-05-30T04:57:36Z")

</div>

[https://github.com/JuliaLang/julia/pull/13412](https://github.com/JuliaLang/julia/pull/13412)  
`Base.call` was deprecated in v0.5, it has been removed in v0.6.  
I guess you could do something like this:

`@generated function (::SavitzkyGolayFilter{M,N})(data::AbstractVector{T}) where {M, N, T}`

---

<div class="post-metadata">

### Author: ![charlesll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charlesll/32/3255_2.png) [@charlesll](https://discourse.julialang.org/u/charlesll)
#### Post date: [May 31, 2017, 5:20am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/3 "2017-05-31T05:20:12Z")

</div>

Thanks, I did not know about that.

I tried the piece of code you suggested but got an error: UndefVarError: M not defined

I don’t understand how I should declare the generated function there… Any idea?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 31, 2017, 6:24am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/4 "2017-05-31T06:24:00Z")

</div>

```julia
immutable SavitzkyGolayFilter{M,N} end
@generated function (::SavitzkyGolayFilter{M,N})(data::AbstractVector{T}) where {M, N, T}
            #Create Jacobian matrix
            J = zeros(2M+1, N+1)
            for i=1:2M+1, j=1:N+1
                J[i, j] = (i-M-1)^(j-1)
            end
            e₁ = zeros(N+1) 
            e₁[1] = 1.0
           
            #Compute filter coefficients
            C = J' \ e₁

            #Evaluate filter on data matrix

            To = typeof(C[1] * one(T)) #Calculate type of output
            expr = quote
                n = size(data, 1)
                smoothed = zeros($To, n)
                @inbounds for i in eachindex(smoothed)
                    smoothed[i] += $(C[M+1])*data[i]
                end
                smoothed
            end

            for j=1:M
                insert!(expr.args[6].args[2].args[2].args, 1,
                    :(if i - $j ≥ 1
                        smoothed[i] += $(C[M+1-j])*data[i-$j]
                      end)
                )
                push!(expr.args[6].args[2].args[2].args,
                    :(if i + $j ≤ n
                        smoothed[i] += $(C[M+1+j])*data[i+$j]
                      end)
                )
            end

            return expr
end

```

This snippet works fine in julia-v0.6. Here are some tests:

```julia
julia> sgf = SavitzkyGolayFilter{3,2}()
SavitzkyGolayFilter{3,2}()

julia> sgf(1:10)
10-element Array{Float64,1}:
 0.952381
 1.90476 
 3.0     
 4.0     
 5.0     
 6.0     
 7.0     
 9.04762 
 8.57143 
 6.38095 

```

is this what you were looking for?

---

<div class="post-metadata">

### Author: ![charlesll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charlesll/32/3255_2.png) [@charlesll](https://discourse.julialang.org/u/charlesll)
#### Post date: [May 31, 2017, 6:45am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/5 "2017-05-31T06:45:21Z")

</div>

> [@Gnimuc](#):
>
> immutable SavitzkyGolayFilter{M,N} end  
> @generated function (::SavitzkyGolayFilter{M,N})(data::AbstractVector{T}) where {M, N, T}  
> #Create Jacobian matrix  
> J = zeros(2M+1, N+1)  
> for i=1:2M+1, j=1:N+1  
> J[i, j] = (i-M-1)^(j-1)  
> end  
> e₁ = zeros(N+1)  
> e₁[1] = 1.0
> 
> ```
> #Compute filter coefficients
> C = J' \ e₁
> 
> #Evaluate filter on data matrix
> 
> To = typeof(C[1] * one(T)) #Calculate type of output
> expr = quote
> n = size(data, 1)
> smoothed = zeros($To, n)
> @inbounds for i in eachindex(smoothed)
> smoothed[i] += $(C[M+1])*data[i]
> end
> smoothed
> end
> 
> for j=1:M
> insert!(expr.args[6].args[2].args[2].args, 1,
> :(if i - $j ≥ 1
> smoothed[i] += $(C[M+1-j])*data[i-$j]
> end)
> )
> push!(expr.args[6].args[2].args[2].args,
> :(if i + $j ≤ n
> smoothed[i] += $(C[M+1+j])*data[i+$j]
> end)
> )
> end
> 
> return expr
> 
> ```
> 
> end

Yes, indeed, it works in Julia V0.6, but not in v0.5.2… I got a first error:

> syntax: space before “{” not allowed in “where {”

and if I correct it by removing the space I get the error

> UndefVarError: M not defined

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 31, 2017, 6:52am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/6 "2017-05-31T06:52:40Z")

</div>

`where` is a new syntax introduced in v0.6. In v0.5.2, your original version should work.

---

<div class="post-metadata">

### Author: ![charlesll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charlesll/32/3255_2.png) [@charlesll](https://discourse.julialang.org/u/charlesll)
#### Post date: [May 31, 2017, 8:15am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/7 "2017-05-31T08:15:37Z")

</div>

Yes, it works in 0.5.2, but is there any chance to make it work for both 0.5.2 and 0.6?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 31, 2017, 8:28am UTC](https://discourse.julialang.org/t/base-call-in-julia-0-6/3983/8 "2017-05-31T08:28:12Z")

</div>

> [@Gnimuc](#):
>
> immutable SavitzkyGolayFilter{M,N} end

the corresponding version of `where` in v0.5 is `@generated function (::SavitzkyGolayFilter{M,N}){M,N,T}(data::AbstractVector{T})` which works fine in both v0.5 and v0.6 🙂
