diff --git a/book/math.md b/book/math.md index 4e2ea59e81e..23073af730a 100644 --- a/book/math.md +++ b/book/math.md @@ -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. diff --git a/book/variables_and_subexpressions.md b/book/variables_and_subexpressions.md index c40daec85ce..c3b55d55c2e 100644 --- a/book/variables_and_subexpressions.md +++ b/book/variables_and_subexpressions.md @@ -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`). diff --git a/book/working_with_lists.md b/book/working_with_lists.md index a77ec8d124f..90e17751015 100644 --- a/book/working_with_lists.md +++ b/book/working_with_lists.md @@ -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: ```bash let colors = [red green blue]