It works.
But using any for x in your new function definition seems very prone to 
stack overflow errors.
What happens if you do:

function $fun_name{T}(x::$new_type{T}...)
or
function $fun_name{T}(x::$new_type...)

I'm not sure how well Julia handles your *t::T=x.* For what is this even 
needed?
You could also do:
function $fun_name{T <: $new_type}(x::T...)

Am Montag, 5. Oktober 2015 15:27:45 UTC+2 schrieb [email protected]:
>
> I am trying to "lift" base functions to allow Nullable types to be used 
> natively I am getting a stack-overflow error with the following code:
>
> # Test with just a few functions
> import Base: get, +, -, /, *, ^
>
> # Function symbols to be lifted
> funs = [:+, :-, :/, :*, :^]
>
> # Generic get function
> # Assume appropriate get functions are written for each type
> function get{T}(x::T)
>   x
> end
>
> S = Union{Symbol, Expr}
>
> # Lifter function
> function lift(fun_name::S, new_type::S)
>   quote
>     function $fun_name{T}(x...;t::T=x)
>     y = Array(Any, length(x))
>     for i in 1:length(x)
>       y[i] = get(x[i])
>     end
>     ret = $fun_name(y...)
>     return $new_type(ret)
>     end
>   end
> end
>
> # Then lift the functions
> for i in funs
>   eval(lift(i, :Nullable))
> end
>
> When I type in anything else into the interpreter in this case f, I get 
> the error message:
>
> WARNING: Caught an exception in the keymap:
> ERROR: StackOverflowError:
> ERROR: UndefVarError: f not defined
>
> Another odd thing about this error is that it doesn't always happen right 
> away and sometimes doesn't happen at all which is odd. I have also tried 
> loading the code by include(scriptfile.jl) but the same thing happens
>
> My Environment: Version Info: 0.5.0-dev+433 (2015-09-29 15:39 UTC), Ubuntu 
> 14.04 x86_64-linux-gnu
>
> DP
>
>
>

Reply via email to