From 38968d8f1335191c65429f89d29b4937ce737d55 Mon Sep 17 00:00:00 2001 From: Reilly Wood Date: Sun, 6 Mar 2022 16:52:04 -0800 Subject: [PATCH 1/4] Move short-hand description from math to subexpression page --- book/math.md | 20 -------------------- book/variables_and_subexpressions.md | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 20 deletions(-) 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..c097b20b2ab 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 + +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`). From 18a5b137b5e5e579fbc8058bdabf84386820581f Mon Sep 17 00:00:00 2001 From: Reilly Wood Date: Sun, 6 Mar 2022 16:56:55 -0800 Subject: [PATCH 2/4] Remove math mode from lists page, no longer necessary --- book/working_with_lists.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/book/working_with_lists.md b/book/working_with_lists.md index a77ec8d124f..c332643adaa 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] From 0aad4dbbfcf17220915967b184ffa669ee1a903b Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sun, 6 Mar 2022 20:21:37 -0500 Subject: [PATCH 3/4] Update working_with_lists.md --- book/working_with_lists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/working_with_lists.md b/book/working_with_lists.md index c332643adaa..90e17751015 100644 --- a/book/working_with_lists.md +++ b/book/working_with_lists.md @@ -43,7 +43,7 @@ let colors = [] = $colors | empty? # true ``` -The `in` and `not in` operators are used to test whether a value is in a list. 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] From c151cac6790cee7e272511bae27d30bbaea812fa Mon Sep 17 00:00:00 2001 From: Reilly Wood Date: Sun, 6 Mar 2022 17:32:13 -0800 Subject: [PATCH 4/4] Mention row condition name --- book/variables_and_subexpressions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/variables_and_subexpressions.md b/book/variables_and_subexpressions.md index c097b20b2ab..c3b55d55c2e 100644 --- a/book/variables_and_subexpressions.md +++ b/book/variables_and_subexpressions.md @@ -64,7 +64,7 @@ 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 +## 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: