Fix deletion using assigning empty against arrays
This pull request fixes #2051, by delaying path deletions. Also fixes #2397, fixes #2422 and fixes #2440.
```sh
 % ./jq -c '(.[] | select(. >= 2)) |= empty' <<< '[1,5,3,0,7]'
[1,0]
 % ./jq -c '.[] |= select(. >= 4)' <<< '[1,5,3,0,7]'
[5,7]
 % ./jq -c '.[] |= select(. == 2)' <<< '[1,5,3,0,7]'
[]
```
<!--
READ THIS FIRST!

If you have a usage question, please ask us on either Stack Overflow (https://stackoverflow.com/questions/tagged/jq) or in the #jq channel (https://web.libera.chat/#jq) on Libera.Chat (https://libera.chat/).

-->

**Describe the bug**

In `(.[].children|.[])|=if has("color") then . else empty end`, `empty` behaves different from regular values.

**To Reproduce**

Run `jq '(.[].children|.[])|=if has("color") then . else empty end' foo.json`, where foo.json is:

``` json
[
    {
        "name": "foo",
        "children": [{
            "name": "foo.0",
            "color": "red"
        }]
    },
    {
        "name": "bar",
        "children": [{
            "name": "bar.0",
            "color": "green"
        },
        {
            "name": "bar.1"
        }]
    },
    {
        "name": "baz",
        "children": [{
            "name": "baz.0"
        },
        {
            "name": "baz.1"
        }]
    }
]
```

Output:

``` json
[
  {
    "name": "foo",
    "children": [
      {
        "name": "foo.0",
        "color": "red"
      }
    ]
  },
  {
    "name": "bar",
    "children": [
      {
        "name": "bar.0",
        "color": "green"
      }
    ]
  },
  {
    "name": "baz",
    "children": [
      {
        "name": "baz.1"
      }
    ]
  }
]
```

**Expected behavior**

I expected this output, which I can get by running `del(.[].children[] | select(has("color") | not))`. 

``` json
[
  {
    "name": "foo",
    "children": [
      {
        "name": "foo.0",
        "color": "red"
      }
    ]
  },
  {
    "name": "bar",
    "children": [
      {
        "name": "bar.0",
        "color": "green"
      }
    ]
  },
  {
    "name": "baz",
    "children": []
  }
]
```

**Environment (please complete the following information):**
 - OS and Version: macOS Monterey (M1 architecture)
 - jq version 1.6

Assigning empty to multiple paths
diff --git a/src/builtin.jq b/src/builtin.jq
index c608555227..192a1e2ab3 100644
--- a/src/builtin.jq
+++ b/src/builtin.jq
@@ -12,24 +12,24 @@ def add: reduce .[] as $x (null; . + $x);
 def del(f): delpaths([path(f)]);
 def _assign(paths; $value): reduce path(paths) as $p (.; setpath($p; $value));
 def _modify(paths; update):
-    reduce path(paths) as $p (.;
+    reduce path(paths) as $p ([., []];
         . as $dot
       | null
       | label $out
-      | ($dot | getpath($p)) as $v
+      | ($dot[0] | getpath($p)) as $v
       | (
           (   $$$$v
             | update
             | (., break $out) as $v
             | $$$$dot
-            | setpath($p; $v)
+            | setpath([0] + $p; $v)
           ),
           (
               $$$$dot
-            | delpaths([$p])
+            | setpath([1, (.[1] | length)]; $p)
           )
         )
-    );
+    ) | . as $dot | $dot[0] | delpaths($dot[1]);
 def map_values(f): .[] |= f;
 
 # recurse

diff --git a/tests/jq.test b/tests/jq.test
index 8a7ccc0eeb..f2a0d352d5 100644
--- a/tests/jq.test
+++ b/tests/jq.test
@@ -1048,6 +1048,19 @@ def inc(x): x |= .+1; inc(.[].a)
 {"a":[{"b":5}]}
 {"a":[{"c":3,"b":5}]}
 
+# #2051, deletion using assigning empty against arrays
+(.[] | select(. >= 2)) |= empty
+[1,5,3,0,7]
+[1,0]
+
+.[] |= select(. % 2 == 0)
+[0,1,2,3,4,5]
+[0,2,4]
+
+.foo[1,4,2,3] |= empty
+{"foo":[0,1,2,3,4,5]}
+{"foo":[0,5]}
+
 .[2][3] = 1
 [4]
 [4, null, [null, null, null, 1]]

{"tests/jqtest": {"run": "PASS", "test": "FAIL", "fix": "PASS"}}
{"test_options": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "regset": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "callback_each_match": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/utf8test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "names": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_utf8": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "simple": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/base64test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "echo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/mantest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "testc": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_syntax": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_back": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "bug_fix": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "scan": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/onigtest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/shtest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "encode": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "callout": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "listcap": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/optionaltest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "user_property": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_regset": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "testcu": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "count": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "syntax": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "sql": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"tests/jqtest": {"run": "PASS", "test": "FAIL", "fix": "PASS"}}
{"passed_count": 28, "failed_count": 0, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/jqtest", "tests/shtest", "callout", "user_property", "echo"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 27, "failed_count": 1, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/shtest", "callout", "user_property", "echo"], "failed_tests": ["tests/jqtest"], "skipped_tests": []}
{"passed_count": 28, "failed_count": 0, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/jqtest", "tests/shtest", "callout", "user_property", "echo"], "failed_tests": [], "skipped_tests": []}