Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow x[1] for scalar x #1843

Merged
merged 1 commit into from
Dec 28, 2012
Merged

allow x[1] for scalar x #1843

merged 1 commit into from
Dec 28, 2012

Conversation

stevengj
Copy link
Member

to be consistent with the treatment of 0-dimensional arrays; note that ndims(x)==0 and length(x)==numel(x)==1 for scalar x.

See also the discussion in issue #1829.

…ensional arrays [since ndims(x)==0 and length(x)==numel(x)==1]
@johnmyleswhite
Copy link
Member

I now have a small concern about this change: it breaks a kind of symmetry between ref and assign. Typically, if one can ref something, one can assign to it as well. This is no longer the case for scalars after this change:

julia> x = 1
1

julia> x[1]
1

julia> x[1] = 2
no method assign(Int64,Int64,Int64)

To me, this is not evidence against the value of defining ref for scalars. It's just evidence for allowing assign to work as well, but I believe that change has to happen outside of base/number.jl because of the immutability of numbers.

@ViralBShah
Copy link
Member

This is not the case, for example with tuples:

julia> a = (5,6,7)
(5,6,7)

julia> a[2]
6

julia> a[2] = 9
no method assign((Int64,Int64,Int64),Int64,Int64)

@johnmyleswhite
Copy link
Member

Tuples seem like a special case. Are there are other examples like that?

@ViralBShah
Copy link
Member

Wouldn't we have more such examples if we had immutable types? Can't think of others right away, but there may be.

@StefanKarpinski
Copy link
Member

Strings too.

@johnmyleswhite
Copy link
Member

You're both right: all immutable types have this property, including strings. Request withdrawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants