-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor monolithic Language Guide into smaller files * Removed old lang-ref file; additional minor fixes
- Loading branch information
1 parent
a9622d1
commit 6504b17
Showing
54 changed files
with
1,803 additions
and
1,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Custom Commands | ||
|
||
## Defining Custom Commands | ||
|
||
## Calling Custom Commands | ||
|
||
## Function Scope | ||
|
||
## Closures | ||
|
||
## Arguments & Parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Declarations | ||
|
||
TODO - `let`, `mut`, `const` and others |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Filters | ||
|
||
A primary goal of Nushell is the ability to easily handle structured data in the pipeline. Nushell contains an extensive set of commands known as "filters" designed to meet these needs. | ||
|
||
A sample of filter commands is listed in this Guide below. For the current list of commands categorized as filters, you can run: | ||
|
||
```nu | ||
help commands | where category == filters | ||
``` | ||
|
||
## Filters vs. Flow Control Statements | ||
|
||
While it's certainly possible to modify structured data using "traditional" flow control statements like `for` or `while`, filters are usually more convenient and (often far) more performant. | ||
|
||
For example: | ||
|
||
- Using a `for` statement to create a list of 50,000 random numbers: | ||
|
||
```nu | ||
timeit { | ||
mut randoms = [] | ||
for _ in 1..50_000 { | ||
$randoms = ($randoms | append (random int)) | ||
} | ||
} | ||
``` | ||
|
||
Result: 1min 4sec 191ms 135µs 90ns | ||
|
||
- Using `each` to do the same: | ||
|
||
```nu | ||
timeit { | ||
let randoms = (1..50_000 | each {random int}) | ||
} | ||
``` | ||
|
||
Result: 19ms 314µs 205ns | ||
|
||
- Using `each` with 10,000,000 iterations: | ||
|
||
```nu | ||
timeit { | ||
let randoms = (1..10_000_000 | each {random int}) | ||
} | ||
``` | ||
|
||
Result: 4sec 233ms 865µs 238ns | ||
|
||
As with many filters, the `each` statement also streams its results, meaning the next stage of the pipeline can continue processing without waiting for the results to be collected into a variable. | ||
|
||
For tasks which can be optimized by parallelization, `par-each` can have even more drastic performance gains. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# `each` and `par-each` | ||
|
||
TODO: Provide detail on the `each` command set | ||
|
||
Note: `each`/`par-each` only iterates over list/table data. To iterate over each key/value pair in a record, first pipe the record through `| transpose key value` to create a table of the keys/values. | ||
|
||
Example: | ||
|
||
```nu | ||
ls | ||
| get 0 | ||
| transpose key value | ||
| inspect | ||
| each {|kv| | ||
$'The value of the "($kv.key) field is "($kv.value)"' | ||
} | ||
``` | ||
|
||
Result: | ||
|
||
```nu | ||
╭─────────────┬──────────────────────────────────╮ | ||
│ description │ list<any> │ | ||
├──────────┬──┴──────────────────────────────────┤ | ||
│ key │ value │ | ||
├──────────┼─────────────────────────────────────┤ | ||
│ name │ CNAME │ | ||
│ type │ file │ | ||
│ size │ 15 │ | ||
│ modified │ 2024-01-31T10:21:46.068408713-05:00 │ | ||
╰──────────┴─────────────────────────────────────╯ | ||
╭───┬──────────────────────────────────────────────────────────────────────────────────────╮ | ||
│ 0 │ The value of the "name field is "CNAME" │ | ||
│ 1 │ The value of the "type field is "file" │ | ||
│ 2 │ The value of the "size field is "15 B" │ | ||
│ 3 │ The value of the "modified field is "Wed, 31 Jan 2024 10:21:46 -0500 (3 months ago)" │ | ||
╰───┴──────────────────────────────────────────────────────────────────────────────────────╯ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Understanding the difference between `get` and `select` | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Filters to select subsets of data | ||
|
||
TODO: `first`/`skip`/`select`/`get`/ cell-paths / `range` and other topics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `where` and `filter` | ||
|
||
TODO |
15 changes: 15 additions & 0 deletions
15
lang-guide/chapters/flow_control/00_flow_control_overview.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
next: ./if-else.md | ||
--- | ||
|
||
# Flow Control | ||
|
||
Nushell includes a number of flow control statements and expressions similar to other languages. | ||
|
||
However, keep in mind that many Nushell operations will be performed using structured data as input and/or output. While structured data can be created using flow control statements in conjunction with mutable variables, a better solution in these cases is to use Filters. | ||
|
||
See: | ||
|
||
```nu | ||
help commands | where category == filter | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `break` | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `continue` | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# if/else | ||
|
||
The `if` expression evaluates a condition and then chooses to run a block based on the condition. | ||
|
||
For example, you can print "yes", based on a true condition: | ||
|
||
```nu | ||
if true { | ||
print yes | ||
} else { | ||
print no | ||
} | ||
``` | ||
|
||
Alternately, you can print "no", based on a false condition: | ||
|
||
```nu | ||
if false { | ||
print yes | ||
} else { | ||
print no | ||
} | ||
``` | ||
|
||
The `else` part of `if` is optional. If not provided, if a condition is false, the `if` expression returns `null`. | ||
|
||
The code that follows the `else` is an expression rather than a block, allowing any number of follow-on `if` expressions as well as other types of expressions. For example, this expression returns 100: `if false { 1 } else 100`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `loop` | ||
|
||
See the [`loop` Help](/commands/docs/loop.html). | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `match` | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `return` | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `try`/`catch` | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `while` | ||
|
||
See the [`while` Help](/commands/docs/while.html). | ||
|
||
_TODO_ - If you can provide detailed information on this command, beyond what is available in the Help, please consider contributing a PR. Click below to ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Functional Programming Concepts in Nu | ||
|
||
Currently a placeholder file. Will not show up in sidebar until content is added and the file is added to `.vuepress/configs/sidebar` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Helpers and debugging commands | ||
|
||
TODO | ||
|
||
## debug | ||
|
||
## metadata | ||
|
||
## error make | ||
|
||
## inspect | ||
|
||
## scope | ||
|
||
## ast | ||
|
||
## others |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Metadata | ||
|
||
Currently a placeholder file. Will not show up in sidebar until content is added and the file is added to `.vuepress/configs/sidebar` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Operators | ||
|
||
## Arithmetic Operators | ||
|
||
- `+` - Plus / Addition | ||
- `-` - Minus / Subtraction | ||
- `*` - Multiply | ||
- `/` - Divide | ||
- `=` - Equal | ||
- `!=` - Not Equal | ||
- `//` - Floor Division | ||
- `<` - Less Than | ||
- `>` - Greater Than | ||
- `<=` - Less Than or Equal To | ||
- `>=` - Greater Than or Equal To | ||
- `mod` - Modulo | ||
- `**` - Pow | ||
|
||
## Bitwise Operators | ||
|
||
Nushell provides support for these bitwise operators: | ||
|
||
- `bit-or` - bitwise or | ||
- `bit-xor` - bitwise exclusive or | ||
- `bit-and` - bitwise and | ||
- `bit-shl` - bitwise shift left | ||
- `bit-shr` - bitwise shift right | ||
|
||
## Other operators | ||
|
||
- `=~` - Regex Match / Contains | ||
- `!~` - Not Regex Match / Not Contains | ||
- `in` - In / Contains (doesn't use regex) | ||
- `not-in` - Not In / Not Contains (doesn't use regex) | ||
- `starts-with` - Starts With | ||
- `ends-with` - Ends With | ||
- `&&` - And | ||
- `and` - And | ||
- `||` - Or | ||
- `or` - Or | ||
|
||
## Brackets | ||
|
||
TODO | ||
|
||
### `(` and `)` | ||
|
||
### `[` and `]` | ||
|
||
### `{` and `}` |
Oops, something went wrong.