Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove math mode mentions, move short hand syntax documentation #257

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions book/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,3 @@ Math operations are evaluated in the follow order (from highest precedence to lo
> 3 * (1 + 2)
9
```

## Short-hand math mode

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.

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:

```
> ls | where size > 10kb
```

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:

```
> ls | where {|$it| $it.size > 10kb }
```

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.

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.
18 changes: 18 additions & 0 deletions book/variables_and_subexpressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,21 @@ We can do a very similar action in a single step using a subexpression path:
```

It depends on the needs of the code and your particular style which form works best for you.

## Short-hand subexpressions (row conditions)

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:

```
> ls | where size > 10kb
```

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:

```
> ls | where $it.size > 10kb
> ls | where ($it.size > 10kb)
> ls | where {|$it| $it.size > 10kb }
```

For short-hand syntax to work, the column name must appear on the left-hand side of the operation (like `size` in `size > 10kb`).
5 changes: 1 addition & 4 deletions book/working_with_lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ let colors = []
= $colors | empty? # true
```

The `in` and `not in` operators are used to test whether a value is in a list.
Operators can only be used in "math mode".
One way to enter math mode is to begin an expression with `=`.
For example:
The `in` and `not-in` operators are used to test whether a value is in a list. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small tweak here, the operators are in and not-in


```bash
let colors = [red green blue]
Expand Down