nushell/crates/nu-cli/src
Ian Manske 4d3283e235
Change append operator to concatenation operator (#14344)
# Description

The "append" operator currently serves as both the append operator and
the concatenation operator. This dual role creates ambiguity when
operating on nested lists.

```nu
[1 2] ++ 3     # appends a value to a list [1 2 3]
[1 2] ++ [3 4] # concatenates two lists    [1 2 3 4]

[[1 2] [3 4]] ++ [5 6]
# does this give [[1 2] [3 4] [5 6]]
# or             [[1 2] [3 4] 5 6]  
```

Another problem is that `++=` can change the type of a variable:
```nu
mut str = 'hello '
$str ++= ['world']
($str | describe) == list<string>
```

Note that appending is only relevant for lists, but concatenation is
relevant for lists, strings, and binary values. Additionally, appending
can be expressed in terms of concatenation (see example below). So, this
PR changes the `++` operator to only perform concatenation.

# User-Facing Changes

Using the `++` operator with a list and a non-list value will now be a
compile time or runtime error.
```nu
mut list = []
$list ++= 1 # error
```
Instead, concatenate a list with one element:
```nu
$list ++= [1]
```
Or use `append`:
```nu
$list = $list | append 1
```

# After Submitting

Update book and docs.

---------

Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com>
2024-11-24 10:59:54 -08:00
..
commands Remove as_i64 and as_f64 (#14258) 2024-11-05 09:28:56 +01:00
completions Change append operator to concatenation operator (#14344) 2024-11-24 10:59:54 -08:00
menus Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
config_files.rs Reduce duplication in history path construction (#13475) 2024-10-11 07:51:50 -05:00
eval_cmds.rs Turn compile errors into fatal errors (#14388) 2024-11-20 19:24:03 +08:00
eval_file.rs Turn compile errors into fatal errors (#14388) 2024-11-20 19:24:03 +08:00
lib.rs Set current working directory at startup (#12953) 2024-09-25 13:04:26 -05:00
nu_highlight.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
print.rs Rely on display_output hook for formatting values from evaluations (#14361) 2024-11-19 21:04:29 +08:00
prompt.rs Make get_env_var return a reference to a Value (#13987) 2024-10-02 13:05:48 +02:00
prompt_update.rs fix ansi bleed over on right prompt (#14357) 2024-11-17 19:47:09 +08:00
reedline_config.rs Cut down unnecessary lint allows (#14335) 2024-11-15 19:24:39 +01:00
repl.rs Remove the NU_DISABLE_IR option (#14293) 2024-11-15 12:09:25 +08:00
syntax_highlight.rs Overhaul $in expressions (#13357) 2024-07-17 16:02:42 -05:00
util.rs Turn compile errors into fatal errors (#14388) 2024-11-20 19:24:03 +08:00
validation.rs Remove old alias implementation (#8797) 2023-04-07 21:09:38 +03:00