cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Docs: a notebook cell's statements, comments and names in one rule

Dami committed bfe621b
commit
bfe621b123de325334fdd81dd39364c87806bb36
parent
02a76805863e2aefa4ac6a944fe164a49dc8bbe2
author
Dami <dami.etoile@gmail.com>
kind
docs risk score 0.0 of 3, Jev's estimate
1 file changed, +47 -8
Mdocs/nushell/notebooks.md55++++++++++++++++++++++++++----
M docs/nushell/notebooks.md +47 -8
@@ -292,9 +292,11 @@ it the context line says what nu said:
292292 Tab asks `nu --ide-complete` too, after the notebook's own names, so it293293 completes flags, subcommands and paths as well as cells and commands.294294 nu doesn't know the variables a notebook binds, so it's asked about the295-cell with `$name` for each named cell and linked file, `$selection` and296-`$sheet` declared before it; a `$sheet.A1:C9` range reads as one297-variable, and `name =` isn't part of what nu reads.295+cell with `$name` for each name the cells assign and each linked file,296+`$selection` and `$sheet` declared before it; a `$sheet.A1:C9` range297+reads as one variable, and the cell's `name =`s ([Names and298+$name](#names-and-name)) aren't part of what nu reads, so what nu says299+is where it points in the cell.298300 299301 Questions to nu run in the background and never on each key: one300302 process for each question after a pause, at most two at a time, each
@@ -346,7 +348,9 @@ printed, and the toolbar how many cells stream; streams run beside the
346348 cells run once, each on its own, without `nu-timeout`. `ii` (or `■`)347349 stops them all, keeping what they printed; running the cell once (`r`)348350 stops its stream first. A stream that ends on its own keeps its output349-as a run does, and one that fails says why.351+as a run does, and one that fails says why. A cell of several statements352+streams its last one's values; the names its earlier lines assign stay353+its own, as a stream hands later cells only its output.350354 351355 The output keeps a stream's last 10,000 values; a sheet it was sent to352356 keeps every row, up to `max-cells`. The rows arrive as the change
@@ -355,10 +359,39 @@ undo history.
355359 356360 ## Names and $name357361 358-A cell that starts `name =` gives its output that name; `n` names a359-cell for you. Later cells read the output as `$name`, a nushell360-variable holding the value, and formulas on any sheet as `nu.name`, or361-a column of it as `name[column]`, once it's [sent to a sheet](#send-to-a-sheet):362+A cell holds one statement or several, a line each (or apart by `;`),363+as a nushell script does; a line starting with `|` goes on with the364+pipeline above it. `name = pipeline` on any line assigns `name`, as365+nushell's `let name = pipeline` does, and the cell's later lines read366+it as `$name`. `#` starts a comment to the end of the line, outside a367+string, as in nushell: a commented-out line assigns and reads nothing.368+369+As in nushell and Jupyter, the cell's output is its last statement's370+value, and the names work across cells by one rule:371+372+- **The cell's name is its output's.** When the last statement is373+ `name = pipeline`, the cell is named `name`; otherwise it has no374+ name until `n` names it, which puts `name =` before its last375+ statement. Other cells read the output as `$name`, and formulas on376+ any sheet as `nu.name`, or a column of it as `name[column]`, once377+ it's [sent to a sheet](#send-to-a-sheet).378+- **Every name assigned goes to later cells.** `$files` in another379+ cell reads the `files` a cell's earlier line assigned, as it was at380+ the end of that cell's run. A cell's name comes first: `$sales` reads381+ the cell named `sales`, and only when no cell is named so, the first382+ cell assigning `sales`.383+- **A cell's own names come first in it.** `$files` after the line384+ assigning `files` reads the cell's own, not another cell's, and isn't385+ a cell it reads.386+387+```nu388+files = ls | where type == file389+$files | where size > 1kb | sort-by size --reverse390+```391+392+This cell has no name (its last line assigns none) and reads no cell;393+its output is the big files, and later cells read `$files` too. Split394+over cells, each named after its output:362395 363396 ```nu364397 files = ls
@@ -366,6 +399,12 @@ big = $files | where size > 1kb
366399 $big | get name | str join ", "367400 ```368401 402+The context line says what a cell reads, the names it sets for later403+cells and its own name (`reads $files; sets $big`). A file keeps each404+cell's output, not the other names it assigned: after opening one, a405+cell reading such a name runs the cell assigning it first, as it does406+a cell that hasn't run.407+369408 A name is letters, digits and `_`, not starting with a digit or `__`;370409 `in`, `env`, `nu`, `it`, `selection` and `sheet` are taken. Two cells371410 can't share a name: the second says so and doesn't run until it's