Terça-feira, 25 de Março de 2014 18:15:28 UTC, Stefan Karpinski escreveu:
>
> First, because it's a total gotcha that putting something in parentheses
> changes its meaning. In Matlab, things are so inconsistent in terms of
> where you can and can't use various syntaxes, that this is hardly the
> biggest issue, but Julia's pretty consistent and this is the *only* place
> in the language where parentheses have such an effect. Second, one really
> ought to avoid dynamically looking up fields like this – the code generated
> for the field lookup is slow and the system doesn't know what type of value
> is returned so it completely destroys type inference. Giving it its own
> syntax just encourages using it.
>
> Sure, sometimes you might *really* want to do this despite the drawbacks,
> but in that case using the getfield(foo,:bar) syntax for it is just fine.
>
I'm perfectly fine with that but PLEASE, add to the manual that one can
also do getfield(foo,symbol("bar"))
>
>
> On Tue, Mar 25, 2014 at 2:07 PM, J Luis <[email protected] <javascript:>>wrote:
>
>>
>>
>> Terça-feira, 25 de Março de 2014 17:47:28 UTC, Stefan Karpinski escreveu:
>>
>>> 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
>>>
>>>
>> I would ... swear that I had tried that too
>>
>>
>>>
>>> The feature is likely to be removed rather than expanded.
>>>
>>
>> Why? It brings a potentially very useful behavior.
>> Better still would be to have the (symbol("bar") be done automatically
>>
>>
>>
>>>
>>>
>>> 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
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>
>