You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**_Rule 1.5:_** This is true throughout the current scope. Even on subsequent lines in a closure or block, `$in` is the same value when used in the first position of _any pipeline_ inside that scope.
137
+
-**_Rule 1.5:_** This is true throughout the current scope. Even on subsequent lines in a closure or block, `$in` is the same value when used in the first position of _any pipeline_ inside that scope.
138
138
139
-
Example:
140
-
141
-
```nu
142
-
[ a b c ] | each {
143
-
print $in
144
-
print $in
145
-
$in
146
-
}
147
-
```
139
+
Example:
148
140
149
-
All three of the `$in` values are the same on each iteration, so this outputs:
141
+
```nu
142
+
[ a b c ] | each {
143
+
print $in
144
+
print $in
145
+
$in
146
+
}
147
+
```
150
148
151
-
```nu
152
-
a
153
-
a
154
-
b
155
-
b
156
-
c
157
-
c
158
-
╭───┬───╮
159
-
│ 0 │ a │
160
-
│ 1 │ b │
161
-
│ 2 │ c │
162
-
╰───┴───╯
163
-
```
149
+
All three of the `$in` values are the same on each iteration, so this outputs:
150
+
151
+
```nu
152
+
a
153
+
a
154
+
b
155
+
b
156
+
c
157
+
c
158
+
╭───┬───╮
159
+
│ 0 │ a │
160
+
│ 1 │ b │
161
+
│ 2 │ c │
162
+
╰───┴───╯
163
+
```
164
164
165
-
* **_Rule 2:_** When used anywhere else in a pipeline (other than the first position), `$in` refers to the previous expression's result:
165
+
-**_Rule 2:_** When used anywhere else in a pipeline (other than the first position), `$in` refers to the previous expression's result:
166
166
167
167
Example:
168
168
169
169
```nushell
170
-
4 # Pipeline input
171
-
| $in * $in # $in is 4 in this expression
172
-
| $in / 2 # $in is now 16 in this expression
173
-
| $in # $in is now 8
170
+
4 # Pipeline input
171
+
| $in * $in # $in is 4 in this expression
172
+
| $in / 2 # $in is now 16 in this expression
173
+
| $in # $in is now 8
174
174
# => 8
175
175
```
176
176
177
-
-**_Rule 2.5:_** Inside a closure or block, Rule 2 usage occurs inside a new scope (a sub-expression) where that "new" `$in` value is valid. This means that Rule 1 and Rule 2 usage can coexist in the same closure or block.
177
+
-**_Rule 2.5:_** Inside a closure or block, Rule 2 usage occurs inside a new scope (a sub-expression) where that "new" `$in` value is valid. This means that Rule 1 and Rule 2 usage can coexist in the same closure or block.
178
178
179
-
Example:
179
+
Example:
180
180
181
-
```nushell
182
-
4 | do {
183
-
print $in # closure-scope $in is 4
181
+
```nushell
182
+
4 | do {
183
+
print $in # closure-scope $in is 4
184
184
185
-
let p = ( # explicit sub-expression, but one will be created regardless
186
-
$in * $in # initial-pipeline position $in is still 4 here
187
-
| $in / 2 # $in is now 16
188
-
) # $p is the result, 8 - Sub-expression scope ends
185
+
let p = ( # explicit sub-expression, but one will be created regardless
186
+
$in * $in # initial-pipeline position $in is still 4 here
187
+
| $in / 2 # $in is now 16
188
+
) # $p is the result, 8 - Sub-expression scope ends
189
189
190
-
print $in # At the closure-scope, the "original" $in is still 4
191
-
print $p
192
-
}
193
-
```
190
+
print $in # At the closure-scope, the "original" $in is still 4
191
+
print $p
192
+
}
193
+
```
194
194
195
-
So the output from the 3 `print` statements is:
195
+
So the output from the 3 `print` statements is:
196
196
197
-
```nu
198
-
4
199
-
4
200
-
8
201
-
```
197
+
```nu
198
+
4
199
+
4
200
+
8
201
+
```
202
202
203
-
Again, this would hold true even if the command above used the more compact, implicit sub-expression form:
203
+
Again, this would hold true even if the command above used the more compact, implicit sub-expression form:
204
204
205
-
Example:
205
+
Example:
206
206
207
-
```nushell
208
-
4 | do {
209
-
print $in # closure-scope $in is 4
210
-
let p = $in * $in | $in / 2 # Implicit let sub-expression
211
-
print $in # At the closure-scope, $in is still 4
212
-
print $p
213
-
}
207
+
```nushell
208
+
4 | do {
209
+
print $in # closure-scope $in is 4
210
+
let p = $in * $in | $in / 2 # Implicit let sub-expression
211
+
print $in # At the closure-scope, $in is still 4
212
+
print $p
213
+
}
214
214
215
-
4
216
-
4
217
-
8
218
-
```
215
+
4
216
+
4
217
+
8
218
+
```
219
219
220
-
* **_Rule 3:_** When used with no input, `$in` is null.
220
+
-**_Rule 3:_** When used with no input, `$in` is null.
0 commit comments