Le samedi 03 janvier 2015 à 08:29 -0800, Ismael VC a écrit :
> I'm trying to port this Python class:
> 
> class Env(dict):
>     "An environment: a dict of {'var':val} pairs, with an outer Env."
>     def __init__(self, parms=(), args=(), outer=None):
>         self.update(zip(parms, args))
>         self.outer = outer
>     def find(self, var):
>         "Find the innermost Env where var appears."
>         return self if (var in self) else self.outer.find(var)
> 
> Haven't even got to the `find` method yet! :( ...this is what I've
> done:
> 
> Environment type:
> 
> julia> type Env
> 
>            data::Dict
> 
>            outer::Nullable{Env}
> 
>            Env() = new(Dict(), Nullable{Env}())
> 
>        end
> 
> 
> Outer constructor:
> 
> julia> function Env(parms::Tuple, args::Tuple, outer::Env)
> 
>            Env(Dict(zip(parms, args)), Nullable(outer))
> 
>        end
> 
> Env
> 
> 
> So far so good:
> 
> julia> parms = (:foo, :bar, :baz);
> 
>  
> 
> julia> args = (1, 2, 3);
> 
>  
> 
> julia> outer = Env()
> 
> Env(Dict{Any,Any}(),Nullable{Env}())
> 
> 
> I've spent a lot of time trying to understand this, without success:
> 
> julia> inner = Env(parms, args, outer)
> 
> ERROR: `convert` has no method matching
> convert(::Type{Env}, ::(Symbol,Symbol,Symbol), ::(Int32,Int32,Int32), ::Env)
> 
>  in call at base.jl:35
> 
> 
> I'll have to go to work before soon, I know this'll be itching my head
> all day long! :P
> 
> What am I doing wrong? or How many things am I doing wrong? :O
This is the error I get with lastest master:
    julia> inner = Env(parms, args, outer)
    ERROR: `convert` has no method matching
     convert(::Type{Env}, ::Dict{Symbol,Int64}, ::Nullable{Env})
     in call at none:2

Actually the error comes from the second call to Env():
    Env(Dict(zip(parms, args)), Nullable(outer))

I think this is because you have overridden the inner constructor
without providing a two-argument version. It works if you move it to an
outer constructor:
       type Env
           data::Dict
           outer::Nullable{Env}
       end
       
       Env() = Env(Dict(), Nullable{Env}())
       
       function Env(parms::Tuple, args::Tuple, outer::Env)
           Env(Dict(zip(parms, args)), Nullable(outer))
       end


Regards

Reply via email to