Skip to content

Commit 38968d8

Browse files
committed
Move short-hand description from math to subexpression page
1 parent d9839a5 commit 38968d8

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

book/math.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,3 @@ Math operations are evaluated in the follow order (from highest precedence to lo
7070
> 3 * (1 + 2)
7171
9
7272
```
73-
74-
## Short-hand math mode
75-
76-
A variation of math mode that Nushell supports is called "short-hand" math mode. This is because it gives you a way of accessing columns using a simple short-hand.
77-
78-
You may have already used this functionality before. If, for example, we wanted to only see rows from `ls` where the entry is at least ten kilobytes, we can write:
79-
80-
```
81-
> ls | where size > 10kb
82-
```
83-
84-
The `where size > 10kb` is a command with two parts: the command name `where` and the short-hand math expression `size > 10kb`. We say short-hand because `size` here is the shortened version of writing `$it.size`. If we look at the fully expanded form, we would see:
85-
86-
```
87-
> ls | where {|$it| $it.size > 10kb }
88-
```
89-
90-
Rather than having to type all this out every time a command needs to work with column data, we use this short-hand mode to access column data.
91-
92-
For the expansion to work, the column name must appear on the left-hand side of the operation. Above, `size` appears on the left-hand side of the comparison, which allows the expression to expand into the full math mode block.

book/variables_and_subexpressions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ We can do a very similar action in a single step using a subexpression path:
6363
```
6464

6565
It depends on the needs of the code and your particular style which form works best for you.
66+
67+
## Short-hand subexpressions
68+
69+
Nushell supports accessing columns in a subexpression using a simple short-hand. You may have already used this functionality before. If, for example, we wanted to only see rows from `ls` where the entry is at least ten kilobytes we can write:
70+
71+
```
72+
> ls | where size > 10kb
73+
```
74+
75+
The `where size > 10kb` is a command with two parts: the command name `where` and the short-hand expression `size > 10kb`. We say short-hand because `size` here is the shortened version of writing `$it.size`. This could also be written in any of the following ways:
76+
77+
```
78+
> ls | where $it.size > 10kb
79+
> ls | where ($it.size > 10kb)
80+
> ls | where {|$it| $it.size > 10kb }
81+
```
82+
83+
For short-hand syntax to work, the column name must appear on the left-hand side of the operation (like `size` in `size > 10kb`).

0 commit comments

Comments
 (0)