{"atom":"regression/itemization-and-list-folds","family":"regression","slug":"itemization-and-list-folds","header":{"atom":"regression/itemization-and-list-folds","kind":"whole-program — a minimal repro, not yet reduced to an atom","source":"curated"},"axes":null,"cols":null,"engines":["rakudo-2026.07","rakupp-3.14.0"],"kinds":["ref","pp"],"defFrom":"rakupp:t/regression/itemization-and-list-folds.raku","counts":{"a":1,"f":0,"d":0,"c":0,"r":0,"n":0},"files":["atoms/regression/itemization-and-list-folds.grid"],"records":[["0001","","# Regression: what a `$` container does to a list, and a batch of List routines.\n#   * a `$` variable ITEMIZES what it stores, so `my $t = (1,2)` is ONE thing:\n#     it does not flatten into a later list (`my @b = $t` has one element) and it\n#     renders with the `$` marker. The marker is dropped for an ARRAY element,\n#     whose slot itemizes anyway — Rakudo prints `[[1, 2],]` but `($(1, 2),)`.\n#   * `list(…)` builds a List of its ARGUMENTS without flattening them; only a\n#     lone non-itemized Positional spreads (the one-arg rule).\n#   * `leg` is the STRING comparison, so `-4 leg -1` is More where `cmp` is Less.\n#   * `.lsb`/`.msb`/`.base` used to truncate a big integer to 64 bits.\n#   * a Whatever in a list PATTERN matches one element, a HyperWhatever a run of\n#     them — and a HyperWhatever on the right of `~~` is a pattern, not a curry.\n#   * `.head`/`.tail`/`.skip` accept any Callable count, not just a WhateverCode.\n#   * `reduce`/`produce` as SUBS delegate to the methods, which is where an\n#     operator's associativity is read off the callable's name. Over an empty\n#     list an operator answers its identity.\n#   * a matcher may be a Regex inside a JUNCTION (`.grep(none /<[aeiou]>/)`) —\n#     the generic `~~` cannot match a regex, so those need the engine.\n# Contract: exit 0 + last line PASS.\nmy @fail;\nsub check($got, $want, $what) { @fail.push(\"$what: got $got want $want\") unless $got eq $want }\n\n# a $ container itemizes\nmy $t = (1, 2);\ncheck($t.raku,        '$(1, 2)', 'a-list-in-a-scalar-is-itemized');\ncheck($t.elems,       '2',       'but-it-still-knows-its-length');\nmy @b = $t;\ncheck(@b.elems,       '1',       'and-does-not-flatten-into-a-list');\ncheck(($t,).raku,     '($(1, 2),)', 'the-marker-shows-inside-a-list');\nmy $arr = [1, 2];\ncheck($arr.raku,      '$[1, 2]',    'an-array-in-a-scalar-too');\ncheck([$arr,].raku,   '[[1, 2],]',  'but-not-as-an-array-element');\nmy %h = a => 1;\nmy $hh = %h;\ncheck($hh.raku,       '${:a(1)}',   'a-hash-in-a-scalar');\ncheck(($hh,).raku,    '(${:a(1)},)', 'a-hash-marker-inside-a-list');\ncheck([$hh,].raku,    '[{:a(1)},]',  'no-hash-marker-as-an-array-element');\n# an itemized hash is one element in list context\nmy @d = $%h;\ncheck(@d.elems,       '1',       'an-itemized-hash-does-not-spread');\nmy @e = %h;\ncheck(@e.elems,       '1',       'a-plain-hash-still-spreads-its-pairs');\n# the plain nesting cases are unchanged\ncheck([[1, 2],].raku,     '[[1, 2],]',      'a-nested-array-literal');\ncheck([1, [2, 3]].raku,   '[1, [2, 3]]',    'an-array-inside-an-array');\ncheck(((1, 2), (3, 4)).raku, '((1, 2), (3, 4))', 'nested-lists');\n\n# list()\ncheck(list(1, 2).raku,          '(1, 2)',         'list-of-two-values');\ncheck(list($t).raku,            '($(1, 2),)',     'list-does-not-open-an-itemized-argument');\ncheck(list(|$t).raku,           '(1, 2)',         'but-a-slip-does');\ncheck(list((1, 2), (3, 4)).raku, '((1, 2), (3, 4))', 'list-does-not-flatten');\ncheck(list([1, 2]).raku,        '(1, 2)',         'one-arg-rule-spreads-a-lone-array');\ncheck(list().raku,              '()',             'list-of-nothing');\ncheck(list(1, 2).^name,         'List',           'list-is-a-list');\n\n# leg is stringwise\ncheck((-4 leg -1).gist, 'More', 'leg-compares-as-strings');\ncheck((10 leg 9).gist,  'Less', 'leg-again');\ncheck((-4 cmp -1).gist, 'Less', 'cmp-is-still-numeric');\ncheck(('a' leg 'b').gist, 'Less', 'leg-on-real-strings');\ncheck((3, -4, 7, -1, 2, 0).sort({ $^b leg $^a }).gist, '(7 3 2 0 -4 -1)', 'sorting-by-leg');\n\n# big integers know all their bits\ncheck((2 ** 81).lsb,            '81', 'lsb-of-a-big-int');\ncheck((2 ** 81).msb,            '81', 'msb-of-a-big-int');\ncheck((2 ** 81).base(2).chars,  '82', 'base-2-of-a-big-int');\ncheck((10 ** 30).base(10),      '1' ~ '0' x 30, 'base-10-of-a-big-int');\ncheck(8.lsb,                    '3',  'lsb-of-a-small-int');\ncheck(255.base(16),             'FF', 'base-16-of-a-small-int');\n\n# Whatever and HyperWhatever in a list pattern\ncheck(((1, 2, 3) ~~ (1, *, 3)).Bool,  'True',  'a-whatever-matches-one-element');\ncheck(((1, 2, 3) ~~ (9, *, 5)).Bool,  'False', 'the-others-must-still-match');\ncheck(((1, 2, 3) ~~ (**, 3)).Bool,    'True',  'a-hyperwhatever-matches-a-run');\ncheck(((1, 2, 3) ~~ (**, 5)).Bool,    'False', 'and-still-has-to-reach-the-end');\ncheck(((1, 2, 4, 5, 6) ~~ (**)).Bool, 'True',  'a-lone-hyperwhatever-matches-anything');\ncheck((() ~~ (**)).Bool,              'True',  'including-nothing');\nmy $hw = **;\ncheck(((1, 2, 3) ~~ $hw).Bool,        'True',  'a-hyperwhatever-value-is-a-pattern-not-a-curry');\n\n# a Callable count\ncheck(<a b c d e>.tail({ $_ - 2 }).gist, '(c d e)', 'tail-with-a-block-count');\ncheck(<a b c d e>.tail(* - 2).gist,      '(c d e)', 'tail-with-a-whatevercode-count');\ncheck(<a b c d e>.head({ $_ - 2 }).gist, '(a b c)', 'head-with-a-block-count');\ncheck(<a b c d e>.skip({ $_ - 2 }).gist, '(d e)',   'skip-with-a-block-count');\ncheck(<a b c d e>.tail(2).gist,          '(d e)',   'a-plain-count-still-works');\n\n# reduce / produce as subs\ncheck((produce &[**], (2, 3, 4)).gist, '(4 81 2417851639229258349412352)', 'the-produce-sub-folds-right');\ncheck(reduce(&infix:<->, (10,)),  '10', 'a-one-element-reduce-is-that-element');\ncheck(reduce(&infix:<->, (10, 3)), '7', 'a-two-element-reduce-still-folds');\ncheck(reduce(&[+], (1, 2, 3)),     '6', 'the-reduce-sub');\ncheck((produce &[+], (1, 2, 3)).gist, '(1 3 6)', 'the-produce-sub');\ncheck(().reduce(&[+]), '0',  'an-empty-plus-reduce-is-zero');\ncheck(().reduce(&[*]), '1',  'an-empty-times-reduce-is-one');\ncheck(().reduce(&[~]), '',   'an-empty-concat-reduce-is-the-empty-string');\ncheck(reduce(&[+], ()), '0', 'the-sub-form-agrees');\n\n# a regex matcher inside a junction\ncheck(<a b c d e f>.grep(none /<[aeiou]>/).gist, '(b c d f)', 'grep-none-of-a-regex');\ncheck(<a b c>.grep(none /a/).gist,        '(b c)', 'grep-none-of-a-simple-regex');\ncheck(<a b 6 d 8 0>.grep(none Int).gist,  '(a b d)', 'grep-none-of-a-type');\ncheck(<a b c>.grep(any(/a/, /c/)).gist,   '(a c)', 'grep-any-of-two-regexes');\ncheck(<a b c>.grep(/b/).gist,             '(b)',   'a-plain-regex-matcher');\ncheck(<a b c>.first(none /a/),            'b',     'first-with-a-junction-matcher');\n\nif @fail { note \"FAILED: @fail.join('; ')\"; say 'FAIL' } else { say 'PASS' }","output PASS","a",["PASS","PASS"],0,[["budget","20s"]]]]}