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

Improvement of documentation of [A, B, C, ...] syntax #19807

Closed
bkamins opened this issue Jan 1, 2017 · 2 comments
Closed

Improvement of documentation of [A, B, C, ...] syntax #19807

bkamins opened this issue Jan 1, 2017 · 2 comments
Labels
domain:docs This change adds or pertains to documentation

Comments

@bkamins
Copy link
Member

bkamins commented Jan 1, 2017

Julia Language Documentation in section 19.1.2 Construction and Initialization states:

The syntax [A, B, C, ...] constructs a 1-d array (vector) of its arguments.

However, the actual behavior is that it can construct a vector where its arguments get converted to a common promotion type if it exists. For example after:

a = [true, false]
b = [1,2]
c = [a, b]

we have that c[1] is:

2-element Array{Int64,1}:
 1
 0

and c1[1] === a is false but c[2] === b is true.

Therefore I would suggest to update the documentation in the following way:

The syntax [A, B, C, ...] constructs a 1-d array (vector) of its arguments. If all arguments have a common promotion type then they get converted to that type. In such a situation mutable arguments are stored in the new array by reference only if they do not have to be converted.

@TotalVerb
Copy link
Contributor

I didn't even know that mutable types behaved this way.

julia> a = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

julia> b = [1.0, 2.0, 3.0]
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> [a, b]
2-element Array{Array{Float64,1},1}:
 [1.0,2.0,3.0]
 [1.0,2.0,3.0]

julia> [a, b][1] === a
false

julia> [a, b][2] === b
true

It is not intuitive. 👍 to the documentation.

@kshyatt kshyatt added the domain:docs This change adds or pertains to documentation label Jan 1, 2017
bdeonovic added a commit to bdeonovic/julia that referenced this issue Jan 2, 2017
bdeonovic added a commit to bdeonovic/julia that referenced this issue Jan 2, 2017
@tkelman
Copy link
Contributor

tkelman commented Jan 2, 2017

this is effectively just #12441 in action

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

4 participants