@@ -119,7 +119,7 @@ that location:
119
119
1 . ** Existing local:** If ` x ` is * already a local variable* , then the existing local ` x ` is
120
120
assigned;
121
121
2 . ** Hard scope:** If ` x ` is * not already a local variable* and assignment occurs inside of any
122
- hard scope construct (i.e. within a let block, function or macro body, comprehension, or
122
+ hard scope construct (i.e. within a ` let ` block, function or macro body, comprehension, or
123
123
generator), a new local named ` x ` is created in the scope of the assignment;
124
124
3 . ** Soft scope:** If ` x ` is * not already a local variable* and all of the scope constructs
125
125
containing the assignment are soft scopes (loops, ` try ` /` catch ` blocks, or ` struct ` blocks), the
@@ -458,8 +458,9 @@ file, if it behaves differently than it did in the REPL, then you will get a war
458
458
459
459
### Let Blocks
460
460
461
- Unlike assignments to local variables, ` let ` statements allocate new variable bindings each time
462
- they run. An assignment modifies an existing value location, and ` let ` creates new locations.
461
+ ` let ` statements create a new * hard scope* block (see above) and introduce new variable
462
+ bindings each time they run. Whereas assignments might reassign a new value to an existing value location,
463
+ ` let ` always creates a new location.
463
464
This difference is usually not important, and is only detectable in the case of variables that
464
465
outlive their scope via closures. The ` let ` syntax accepts a comma-separated series of assignments
465
466
and variable names:
@@ -517,7 +518,7 @@ julia> Fs[2]()
517
518
```
518
519
519
520
Since the ` begin ` construct does not introduce a new scope, it can be useful to use a zero-argument
520
- ` let ` to just introduce a new scope block without creating any new bindings:
521
+ ` let ` to just introduce a new scope block without creating any new bindings immediately :
521
522
522
523
``` jldoctest
523
524
julia> let
@@ -531,7 +532,16 @@ julia> let
531
532
```
532
533
533
534
Since ` let ` introduces a new scope block, the inner local ` x ` is a different variable than the
534
- outer local ` x ` .
535
+ outer local ` x ` . This particular example is equivalent to:
536
+
537
+ ``` jldoctest
538
+ julia> let x = 1
539
+ let x = 2
540
+ end
541
+ x
542
+ end
543
+ 1
544
+ ```
535
545
536
546
### Loops and Comprehensions
537
547
0 commit comments