Julia: change foo[:bar] interfaces to foo.bar

Created on 18 Dec 2017  路  5Comments  路  Source: JuliaLang/julia

Now that #24960 is merged, it's important that we think through its implications. In particular, for types where we used a foo[:bar] API, we should strongly consider changing it to foo.bar using getproperty.

In particular, I'm thinking of factorization objects like qrfact, where we currently use QR[:Q]. It seems like QR.Q would be a lot more natural.

decision linear algebra

Most helpful comment

I'm almost done with this so I'll open a PR shortly.

All 5 comments

I'm almost done with this so I'll open a PR shortly.

Besides factorization objects, the only other place where this idiom seems to be used is getindex(m::RegexMatch, name::Symbol), which should possibly be changed too?

I can work on that one, since I've been doing some other work that touches regexes anyway.

Although that's a little different since we do want to do m.match and m.captures to get at what the match object matched and captured. I guess I could change m.captures to a RegexCaptures object that is both indexable like an array of strings and that you can do m.captures.name on. But I'm not sure that's worth it since writing m[:name] is quite a bit shorter anyway.

I think we should keep m[:name] for Regex (or use m["name"]?). The QR change seems pretty clearly better though.

Was this page helpful?
0 / 5 - 0 ratings