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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next Next commit
Move short-hand description from math to subexpression page
  • Loading branch information
rgwood committed Mar 7, 2022
commit 38968d8f1335191c65429f89d29b4937ce737d55
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
Copy link
Contributor

Choose a reason for hiding this comment

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

These are called "row conditions" in the engine code. Not sure if that's clearer or less clear than "short-hand subexpressions"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the header to ## Short-hand subexpressions (row conditions). Think that strikes a balance between:

  1. Fitting the context of the Variables and Subexpressions page
  2. Tying things back to the engine's terminology


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`).