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

Improve docs for immutable composite type behavior as function arguments #14801

Closed
GravityAssisted opened this issue Jan 26, 2016 · 6 comments
Closed
Labels
docs This change adds or pertains to documentation

Comments

@GravityAssisted
Copy link

In continuation from: https://groups.google.com/d/msg/julia-users/ZjOHONlVhsQ/eUBW51B5CgAJ

The statement from the docs:

"An object with an immutable type is passed around (both in assignment statements and in function calls) by copying, whereas a mutable type is passed around by reference."

is misleading and may not always be true (see discussion posted above).

My limited understanding and discussion with people on google groups suggests that the compiler is free to either copy or reference immutables (both singular or array of composite types ).

thanks,
Nitin

@tkelman tkelman added the docs This change adds or pertains to documentation label Jan 26, 2016
@JeffBezanson
Copy link
Member

+1 Indeed, the whole point of immutable is that you can't tell whether the value was "copied".

@goelakash
Copy link
Contributor

So from:

To recap, two essential properties define immutability in Julia:

  • An object with an immutable type is passed around (both in assignment statements and in function calls) by copying, whereas a mutable type is passed around by reference.
  • It is not permitted to modify the fields of a composite immutable type.

Could be changed to:

So essentially, It is not permitted to modify the fields of a composite immutable type.

@315234
Copy link
Contributor

315234 commented Mar 12, 2016

Is the following a manifestation of this issue?

function normalize!(data)
    data /= data[end]
end

data = fill(3.0, 10)
normalize!(data)
println(data[end])

I would expect this to print "1.0", instead it prints "3.0".

@yuyichao
Copy link
Contributor

No, it is simply because /= is not a in-place update operator #249

@StefanKarpinski
Copy link
Member

Even if /= were an in-place operator, this would still not work because floats are immutable and Julia functions cannot change bindings in the calling scope.

@mbauman
Copy link
Member

mbauman commented Apr 9, 2021

This line fortunately no longer appears in the docs.

@mbauman mbauman closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

8 participants