# Variable binding: (re-) assignment, argument passing, \`let\`, scope

**URL:** <https://discourse.julialang.org/t/variable-binding-re-assignment-argument-passing-let-scope/16840>\
**Category:** New to Julia\
**Tags:** documentation\
**Created:** [October 26, 2018, 11:19pm UTC](https://discourse.julialang.org/t/variable-binding-re-assignment-argument-passing-let-scope/16840 "2018-10-26T23:19:03Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discourse.julialang.org/u/Vic)\
**Post date:** [October 29, 2018, 11:28pm UTC](https://discourse.julialang.org/t/variable-binding-re-assignment-argument-passing-let-scope/16840/24 "2018-10-29T23:28:56Z")

</div>

> (he is always right, even though it is sometimes necessary to meditate on his words).

I’m sure you wanted to say he is most often right. NO ONE IS ALWAYS RIGHT  
(& I’m not implying anything about him, either from this thread or in general).  
I’m emphasizing this because it’s important to uphold ~~preserve~~ the culture ~~that we have at least in western world~~ , that one should always question any authority, if he/she thinks so (of course with due respect). Else, sooner or later a mistake surfaces, and the more people believe without questioning, the graver the consequences.

Relative to you or yuyichao, I have next to nothing specific compiler knowledge. But here’s what I understand, by an analogy.  
Say I’m given that:

```julia
x= 234 *2342
y=908 - x
y= 234 +1001
z= 3*(y+ 23 -23 -23 -23 +23 +5)/(3*1000*y)

```

And I’m asked to what is z.  
Then I break the solving in 2 parts: simplification and actual-computation

1. Simplification. I’ll look at what’s asked, and realize I only need `y`, and so ignore `x` completely. Also, ignore the older `y`.  
Then , in expression for z, I’ll try scan the expression, notice cancellations possible and do that. Eventually get an equivalent problem:

```julia
y=234+1001
z=(y- 23 +5)/(1000*y)

```

2. Computation. Compute y, store result. Substitute for y in z. Finally do all operations in expression of z.

The Ist phase to me is one an optimizing compiler could do, at a very high level; and the “execution” would be 2nd step.

I can indeed see that the computer is not going to do the instructions in a top-down fashion as I presented the original program/problem, but instead take the whole program as a whole and try to give an answer that would be equivalent to running each statement in turn, but in a much smarter &faster way.  
On the other hand, if given those instructions one by one, like in REPL, the computer is forced to follow them literally.

So I can see now what @yuyichao might have meant when he was saying that an instruction like `x=100` _may or may not_ result in storing 100 at some place in memory. It really depends on the other instructions next to `x=100`, given as a block or not, and context.

And I had in mind REPL, and 1 instruction at a time, when I was surprised to hear that; it was like a religious authority telling you that the earth is flat.

> [@yuyichao](#):
>
> > FWIW, I agree with your approach to understanding: Mentally compile your code into unoptimized assembly; then allow llvm to work its magic to give you the assembly you should have written in the first place.
> 
> That is a very good way to understand compiler and I use that too. And that’s what I really recommend ppl to do to be able to write efficient code.

I guess in complex problems it helps to do the simplification step I mentioned above yourself, to help the compiler.

---

_[View the full topic](https://discourse.julialang.org/t/variable-binding-re-assignment-argument-passing-let-scope/16840)._
