You just need to convert the string to a symbol first:

julia> type Foo
         bar
         baz
       end

julia> foo = Foo(1,2)
Foo(1,2)

julia> foo.("bar")
ERROR: type: getfield: expected Symbol, got ASCIIString

julia> foo.(symbol("bar"))
1


The feature is likely to be removed rather than expanded.


On Tue, Mar 25, 2014 at 1:36 PM, J Luis <[email protected]> wrote:

>
> This is a somewhat dubious feature borrowed from Matlab. I think we should
>> deprecate and then drop it.
>>
>
> That furthermore does not work like the Matlab one ... but would be nice
> if it did
>
>
>
>>
>>
>> On Mon, Mar 24, 2014 at 11:01 PM, Sam L <[email protected]> wrote:
>>
>>> After some experimentation, it looks like second way takes a symbol or
>>> variable who's value is a symbol.
>>>
>>> julia> type MyType; a::Int; end
>>>
>>> julia> x = MyType(3)
>>> MyType(3)
>>>
>>> julia> x.a
>>> 3
>>>
>>> julia> x.(a)
>>> ERROR: a not defined
>>>
>>> julia> x.(:a)
>>> 3
>>>
>>> julia> b = :a
>>> :a
>>>
>>> julia> x.(b)
>>> 3
>>>
>>>
>>> On Monday, March 24, 2014 7:46:38 PM UTC-7, J Luis wrote:
>>>>
>>>> The doc of getfield says
>>>>
>>>> getfield(*value*, *name::Symbol*)
>>>>
>>>> Extract a named field from a value of composite type. The syntax a.bcalls
>>>> getfield(a, :b), and the syntax a.(b) calls getfield(a, b).
>>>>
>>>> but when I try the a.(b) variation, it errors (or it's me who errors?)
>>>>
>>>> julia> gmt_modules.write
>>>> "<?I,>?O"
>>>>
>>>> julia> gmt_modules.(write)
>>>> ERROR: type: getfield: expected Symbol, got Function
>>>>
>>>>
>>>>
>>>>
>>>>
>>

Reply via email to