# To know if there is a Julia analogue of some Modern Fortran declarations within subroutines

**URL:** https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861
**Category:** New to Julia
**Tags:** question
**Created:** [November 26, 2022, 5:44pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861 "2022-11-26T17:44:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![martinmestre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinmestre/32/215857_2.png) [@martinmestre](https://discourse.julialang.org/u/martinmestre)
#### Post date: [November 26, 2022, 5:44pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/1 "2022-11-26T17:44:38Z")

</div>

Hi all,  
I would like to know if it is possible to define the intention of the function arguments as in Fortran’s:  
`intent(in)`,` intent(out)` and `intent(inout)`.  
I used them a lot in Modern Fortran in order to be sure that the intention inside a subroutine is not changed by mistake. Here in Julia I use functions instead of subroutines, but would like to know if there is a standard method to fix the intention of its arguments.  
Thank you very much,  
Martín

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [November 26, 2022, 6:05pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/2 "2022-11-26T18:05:01Z")

</div>

No, there isn’t. [Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/functions/#Argument-Passing-Behavior)  
Some arguments may be mutable (arrays), but others are immutable. Example:

```julia
julia> f(x) = (x = 4)                                                                                                                                                                   
f (generic function with 1 method)                                                                                                                                                      
                                                                                                                                                                                        
julia> x = 5                                                                                                                                                                            
5                                                                                                                                                                                       
                                                                                                                                                                                        
julia> f(x)                                                                                                                                                                             
4                                                                                                                                                                                       
                                                                                                                                                                                        
julia> x                                                                                                                                                                                
5       

```

---

<div class="post-metadata">

### Author: ![martinmestre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinmestre/32/215857_2.png) [@martinmestre](https://discourse.julialang.org/u/martinmestre)
#### Post date: [November 26, 2022, 6:26pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/3 "2022-11-26T18:26:24Z")

</div>

Thanks! I have a questions regarding your example. If `f(x)` returns the expression `(x=4)` as output, should the results of doing in the repl:  
`f(3)`  
and  
`3=4`  
be equal? But they aren’t as the former gives just `4` and the latter gives an error message.  
Do you know the reason? Best.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [November 26, 2022, 6:31pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/4 "2022-11-26T18:31:22Z")

</div>

The `f(x)` returns the result of the last expression, which is 4. So, `f(x) == 4` should be true.

---

<div class="post-metadata">

### Author: ![martinmestre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinmestre/32/215857_2.png) [@martinmestre](https://discourse.julialang.org/u/martinmestre)
#### Post date: [November 26, 2022, 6:33pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/5 "2022-11-26T18:33:00Z")

</div>

So `f(x)=(x=4)` returns just` 4`, not` (x=4)`, right ?

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [November 26, 2022, 6:33pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/6 "2022-11-26T18:33:12Z")

</div>

Correct.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [November 26, 2022, 7:21pm UTC](https://discourse.julialang.org/t/to-know-if-there-is-a-julia-analogue-of-some-modern-fortran-declarations-within-subroutines/90861/7 "2022-11-26T19:21:38Z")

</div>

```julia
x = y

```

is _ **always** _ assignment, _ **not** _ mutation: [Variables · The Julia Language](https://docs.julialang.org/en/v1.10-dev/manual/variables/#man-assignment-expressions).

In addition to that, Julia, like many other dynamic languages, uses [pass-by-sharing](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing), which can briefly summarised as “mutable objects can be mutated, immutable objects cannot”: [Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/functions/#Argument-Passing-Behavior). So no, there is no risk of redefining 3=4. In this way you can also see that all immutable arguments are always strictly “in”, all mutable arguments are potentially “inout”. What actually happens depends on what the method does in its body.
