Skip to content

Commit d4b838b

Browse files
committed
Incorporated feedback from review
1 parent ccd2ffa commit d4b838b

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

book/how_nushell_code_gets_run.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Compiled ("static") languages also tend to have a way to convey some logic at co
347347

348348
- C's preprocessor
349349
- Rust macros
350-
- [Zig's comptime](https://kristoff.it/blog/what-is-zig-comptime)
350+
- [Zig's comptime](https://kristoff.it/blog/what-is-zig-comptime), which was an inspiration for Nushell's parse-time constant evaluation.
351351

352352
There are two reasons for this:
353353

book/thinking_in_nu.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ curl -s https://api.github.com/repos/nushell/nushell/contributors | jq '.[].logi
2222
Nushell has many other similarities with Bash (and other shells) and many commands in common.
2323

2424
::: tip
25-
While the above commandline works, in Nushell there's just no need to use the `curl` and `jq` commands for this, since Nushell has a built-in [`http get` command](/commands/docs/http_get.md) and handles JSON data natively. For example:
25+
Bash is primarily a command interpreter which runs external commands. Nushell provides many of these as cross-platform, built-in commands.
26+
27+
While the above commandline works in both shells, in Nushell there's just no need to use the `curl` and `jq` commands. Instead, Nushell has a built-in [`http get` command](/commands/docs/http_get.md) and handles JSON data natively. For example:
2628

2729
```nu
2830
http get https://api.github.com/repos/nushell/nushell/contributors | select login contributions
@@ -209,12 +211,20 @@ to combine simple commands together to achieve complex results.
209211

210212
## Think of Nushell as a Compiled Language
211213

212-
In Nushell, there are exactly two, high-level stages when running code:
214+
In Nushell, there are exactly two, separate, high-level stages when running code:
215+
216+
1. _Stage 1 (Parser):_ Parse the **_entire_** source code
217+
2. _Stage 2 (Engine):_ Evaluate the **_entire_** source code
218+
219+
It can be useful to think of Nushell's parsing stage as _compilation_ in [static](./how_nushell_code_gets_run.md#dynamic-vs-static-languages) languages like Rust or C++. By this, we mean that all of the code that will be evaluated in Stage 2 must be **_known and available_** during the parsing stage.
220+
221+
::: important
222+
However, this also means that Nushell cannot currently support an `eval` construct as with _dynamic_ languages such as Bash or Python.
223+
:::
213224

214-
1. _Stage 1 (Parser):_ Parse the entire source code
215-
2. _Stage 2 (Engine):_ Evaluate the entire source code
225+
### Features Built on Static Parsing
216226

217-
The Nushell Parser is key to many features of Nushell and its REPL, such as:
227+
On the other hand, the **_static_** results of Parsing are key to many features of Nushell its REPL, such as:
218228

219229
- Accurate and expressive error messages
220230
- Semantic analysis for earlier and robust detection of error conditions
@@ -229,13 +239,9 @@ The Nushell Parser is key to many features of Nushell and its REPL, such as:
229239
- (Future) Formatting
230240
- (Future) Saving IR (Intermediate Representation) "compiled" results for faster execution
231241

232-
It can be useful to think of Nushell's parsing stage as _compilation_ in [static](./how_nushell_code_gets_run.md#dynamic-vs-static-languages) languages like Rust or C++. By this, we mean that all of the code that will be evaluated in Stage 2 must be **_known and available_** during the parsing stage.
242+
### Limitations
233243

234-
::: important
235-
However, this also means that Nushell cannot currently support an `eval` construct as with _dynamic_ languages such as Bash or Python.
236-
:::
237-
238-
This often leads to confusion for users coming to Nushell from languages where an `eval` is available.
244+
The static nature of Nushell often leads to confusion for users coming to Nushell from languages where an `eval` is available.
239245

240246
Consider a simple two-line file:
241247

@@ -258,7 +264,7 @@ The following examples use the [`source` command](/commands/docs/source.md), but
258264

259265
:::
260266

261-
### Example: Dynamically Generating Source
267+
#### Example: Dynamically Generating Source
262268

263269
Consider this scenario:
264270

@@ -290,7 +296,7 @@ The limitation only occurs when both are parsed _together_ as a single expressio
290296
See the [REPL](./how_nushell_code_gets_run.md#the-nushell-repl) section in _"How Nushell Code Gets Run"_ for more explanation.
291297
:::
292298

293-
### Example: Dynamically Creating a Filename to be Sourced
299+
#### Example: Dynamically Creating a Filename to be Sourced
294300

295301
Another common scenario when coming from another shell might be attempting to dynamically create a filename that will be sourced:
296302

@@ -351,7 +357,7 @@ source $"($my_path)/common.nu"
351357
See [Parse-time Constant Evaluation](./how_nushell_code_gets_run.md#parse-time-constant-evaluation) for more details.
352358
:::
353359

354-
### Example: Change to a different directory (`cd`) and `source` a file
360+
#### Example: Change to a different directory (`cd`) and `source` a file
355361

356362
Here's one more — Change to a different directory and then attempt to `source` a file in that directory.
357363

@@ -388,7 +394,7 @@ Nushell is designed to use a single Parsing stage for each expression or file. T
388394

389395
## Variables are Immutable by Default
390396

391-
Another common surprise when coming from other languages is that Nushell variables are immutable by default. Coming to Nushell, you'll want to spend some time becoming familiar with working in a more functional style, as this tends to help write code that works best with immutable variables.
397+
Another common surprise when coming from other languages is that Nushell variables are immutable by default. While Nushell has optional mutable variables, many of Nushell's commands are based on a functional-style of programming which requires immutability.
392398

393399
Immutable variables are also key to Nushell's [`par-each` command](/commands/docs/par-each.md), which allows you to operate on multiple values in parallel using threads.
394400

@@ -417,7 +423,9 @@ ls | each { |row|
417423

418424
The [`cd`](/commands/docs/cd.md) command changes the `PWD` environment variables, but this variable change does not survive past the end of the block. This allows each iteration to start from the current directory and then enter the next subdirectory.
419425

420-
Having a scoped environment makes commands more predictable, easier to read, and when the time comes, easier to debug. Nushell also provides helper commands like [`load-env`](/commands/docs/load-env.md) as a convenient way of loading multiple updates to the environment at once.
426+
Having a scoped environment makes commands more predictable, easier to read, and when the time comes, easier to debug. It's also another feature that is key to the `par-each` command we discussed above.
427+
428+
Nushell also provides helper commands like [`load-env`](/commands/docs/load-env.md) as a convenient way of loading multiple updates to the environment at once.
421429

422430
::: tip See Also
423431
[Environment - Scoping](./environment.md#scoping)

0 commit comments

Comments
 (0)