Thank you! For this question, invoke indeed a good solution :)

How about a more general case. For example, I already have a function foo
foo(X::Int)=X+1
in the environment.

Then I want to overload foo to forbid negative input:
function foo(X::Int)
    @assert(X>=0,"X should be a positive number.")
    invoke(foo,(Int,),X)#Here, I hope to call the original definition of 
foo.
end

However, invoke doesn't work as I expected in this case. Is there any other 
solution? 



On Sunday, April 26, 2015 at 8:40:06 AM UTC+2, Sam L wrote:
>
> See ?invoke.
>
> display(X::Vector)=length(X)>10?print("Too long to show."): 
> invoke(display, (Any,), X)
>
> On Saturday, April 25, 2015 at 10:41:39 PM UTC-7, Jerry Xiong wrote:
>>
>> For example, if I want to overload the Base.display(::Vector) to repress 
>> the display when the vector is too long, I coded as below:
>> julia> import Base.display
>>
>> julia> display(X::Vector)=length(X)>10?print("Too long to show."):Base.
>> display(X)
>> display (generic function with 17 methods)
>>
>> julia> display([1,2,3])
>> ERROR: stack overflow
>>  in display at none:1 (repeats 39998 times)
>>
>> I want to call the original Base.display when the length of vector is 
>> less than 10, but it is became a dead recurring. Is there any way to do it?
>>
>

Reply via email to