Julia's argument passing behavior

From the Julia documentation:

Julia's functional arguments follow a convention sometimes called "pass-by-sharing" ...

  • Does this mean that changing mutable objects inside a function will also change the object in the call area?

  • But if the object is immutable, then changing it inside the function will not affect the object in the call area? In this case, is there any difference from passing by value?

  • I am right that the addition ! at the end of a function, is it just a convention, but has no semantic meaning in compilation?

  • What would be the best way to convey the value of a custom composite type mutable object? I tried using copy() but got an error stating that copy() not defined for my custom type. I think I need to extend copy() for my custom type. Where can I find copy() definitions for other types (would like to use them as a reference when writing extensions)?

+5
source share
1 answer
  • Does this mean that changing mutable objects inside a function will also change the object in the call area?

Short answer Yes . But keep this: “changing an object” is a broad concept, is a new memory cell assigned? If you redistribute a local variable in the function area, the line with the caller will be split. → more about mutation and assignment

  1. But if the object is immutable, then changing it inside the function will not affect the object in the call area? Isn’t it in this case different from transmission by value?

This is because an immutable does not change, so the only way to change it is to assign a new memory cell, and thus the split line will be split.

  1. I am right that the addition! at the end of a function, is it just a convention, but has no semantic meaning in compilation?

Yes you are right.

  1. What....?

Use deepcopy() instead.

+2
source

Source: https://habr.com/ru/post/1239870/


All Articles