In OP's case, when I'm writing the function myself, I will do this:
function test(mystr)
convert(Symbol, mystr)
# code
end
It's a bit verbose, but allows the method to be called with anything
convertible to a Symbol without having to define a whole bunch of new
methods. The convert method when mystr is a Symbol peforms almost 0 work.
It doesn't solve your want for a simple form, but there's no repetition
necessary.
On Tuesday, 11 February 2014 17:30:21 UTC-6, Fil Mackay wrote:
>
> Just wondering if there is an operator to easily perform known conversion.
> Say I have a function that takes a Symbol, and I want it to accept a String
> as well:
>
> function test(s::Symbol)
> end
>
> What I want to do is say, "yes I know this is not a Symbol - so please
> convert() it"
>
> mystr = "foo"
> test(mystr::Symbol)
>
> This would translate to:
>
> mystr = "foo"
> test(convert(Symbol, mystr))
>
> Is there any such operator? I would have thought doing this with the
> current type assert would make sense?
>
> Regards, Fil.
>
>