hclang 0.53.0 → 0.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,7 +82,8 @@ cd hclang
82
82
  deno task hc
83
83
  ```
84
84
 
85
- This will launch the interactive HC interpreter.
85
+ This will launch the interactive HC interpreter. The `hc` task regenerates the
86
+ local, gitignored HC bundle automatically on a fresh clone.
86
87
 
87
88
  ### Run Tests
88
89
 
@@ -112,6 +113,11 @@ The root `deno.json` provides several tasks:
112
113
  | `deno task build:npm` | Generate the Node.js CLI package in `dist/npm` |
113
114
  | `deno task test:npm` | Pack and smoke-test the CLI package through `npx` |
114
115
 
116
+ `test:doc` automatically discovers every `hc/*.hc` file with an HC shebang and
117
+ an executable `; source` / `# expected` pair. It runs each testdoc in an
118
+ independent session; there is no file list to update. `test:bs` remains a
119
+ convenient focused command for BitScheme alone.
120
+
115
121
  ### BitScheme
116
122
 
117
123
  [BitScheme](hc/BitScheme.hc) is a specialized scripting language for
@@ -175,8 +181,16 @@ deno task hc
175
181
  This checks formatting and lint without fixing sources, then runs the test
176
182
  suite. Use `deno task fix` to format and apply lint fixes.
177
183
 
178
- `deno task bundle:check` checks bundled HC sources without rewriting them;
179
- after editing `hc/*.hc`, regenerate them with `deno task bundle:embed`.
184
+ A pull request from a branch in this repository is formatted in CI. When
185
+ files change, CI pushes a `style: deno fmt` commit onto the branch; pull it
186
+ before the next `deno task test`. Pushes to the default branch and fork pull
187
+ requests fail `deno fmt --check` on drift.
188
+
189
+ Build, test, and publish tasks automatically regenerate the bundled HC
190
+ sources from `hc/*.hc`. `deno task bundle:check` is available to verify the
191
+ generated module when needed. Before running raw `deno check`, a bare
192
+ `deno test`, or editor type-checking on a fresh clone, initialize that
193
+ gitignored module once with `deno task bundle:embed`.
180
194
 
181
195
  ### Project Structure
182
196
 
@@ -1356,6 +1356,701 @@ export const HC_SOURCES = new Map([
1356
1356
  "",
1357
1357
  ].join("\n"),
1358
1358
  ],
1359
+ [
1360
+ "hc/cart-zip.hc",
1361
+ [
1362
+ "#!/usr/bin/env hc",
1363
+ "```",
1364
+ "Cart and Zip: derived pairing patterns (#498)",
1365
+ "",
1366
+ "These are executable HC testdoc expectations, not new evaluator primitives.",
1367
+ "Cart pairs every immediate element of A with every immediate element of B.",
1368
+ "Zip pairs elements at corresponding addresses. Composition and arrangement",
1369
+ "remain separate choices.",
1370
+ "",
1371
+ "The testdoc runner evaluates each '; ' example and checks the following '# '",
1372
+ "expectation. Run with deno task test:doc.",
1373
+ "",
1374
+ "## Pair construction",
1375
+ "",
1376
+ "```",
1377
+ "; [1, 10]",
1378
+ "# [1, 10]",
1379
+ "```",
1380
+ "",
1381
+ "## Cartesian pairing: nested and flat arrangements",
1382
+ "",
1383
+ "```",
1384
+ "; .A [1, 2];",
1385
+ "; .B [10, 20, 30];",
1386
+ "; A & {.a _; B & {[a, _]}}",
1387
+ "# [[[1, 10], [1, 20], [1, 30]], [[2, 10], [2, 20], [2, 30]]]",
1388
+ "; A &| {.a _; B & {[a, _]}}",
1389
+ "# [[1, 10], [1, 20], [1, 30], [2, 10], [2, 20], [2, 30]]",
1390
+ "```",
1391
+ "",
1392
+ "## Cartesian pairing: empty sources and repeated occurrences",
1393
+ "",
1394
+ "```",
1395
+ "; [] & {.a _; B & {[a, _]}}",
1396
+ "# []",
1397
+ "; A & {.a _; [] & {[a, _]}}",
1398
+ "# [[], []]",
1399
+ "; A &| {.a _; [] & {[a, _]}}",
1400
+ "# []",
1401
+ "; [1, 1] &| {.a _; [2, 2] & {[a, _]}}",
1402
+ "# [[1, 2], [1, 2], [1, 2], [1, 2]]",
1403
+ "```",
1404
+ "",
1405
+ "## Cartesian pairing: nested children are paired as immediate elements",
1406
+ "",
1407
+ "```",
1408
+ "; [[1], [2]] &| {.a _; [[3], [4]] & {[a, _]}}",
1409
+ "# [[[1], [3]], [[1], [4]], [[2], [3]], [[2], [4]]]",
1410
+ "```",
1411
+ "",
1412
+ "## Zip: corresponding positions",
1413
+ "",
1414
+ "The doubled map yields [address, value]. Its address can be applied to B.",
1415
+ "",
1416
+ "```",
1417
+ "; .C [10, 20];",
1418
+ "; A && {[_.1, C (_.0)]}",
1419
+ "# [[1, 10], [2, 20]]",
1420
+ "; [] && {[_.1, C (_.0)]}",
1421
+ "# []",
1422
+ "; [1, 1] && {[_.1, C (_.0)]}",
1423
+ "# [[1, 10], [1, 20]]",
1424
+ "```",
1425
+ "",
1426
+ "## Zip includes the property plane under doubled iteration",
1427
+ "",
1428
+ "A property-bearing source does not have the same correspondence domain as",
1429
+ "an element-only list. This expectation pins the documented && behavior.",
1430
+ "",
1431
+ "```",
1432
+ "; [.meta 9; 1, 2] && {_}",
1433
+ "# [[.meta, 9], [.0, 1], [.1, 2]]",
1434
+ "```",
1435
+ "",
1436
+ "## Composition after pairing",
1437
+ "",
1438
+ "```",
1439
+ "; (A &| {.a _; B & {[a, _]}}) & {(_.0 * _.1)}",
1440
+ "# [10, 20, 30, 20, 40, 60]",
1441
+ "```",
1442
+ "",
1443
+ "## Flop: concatenate by folding Apply over immediate children",
1444
+ "",
1445
+ "Flop is the FOIST name for repeated Apply: B | A threads A as the",
1446
+ "receiver while visiting each immediate child of B. It is a derived",
1447
+ "left fold, not argument spreading or a new HC evaluator primitive.",
1448
+ "",
1449
+ "```",
1450
+ "; [3, 4] | [1, 2]",
1451
+ "# [1, 2, 3, 4]",
1452
+ "; [] | [1, 2]",
1453
+ "# [1, 2]",
1454
+ "; [3, 4] | []",
1455
+ "# [3, 4]",
1456
+ "; [2, 2] | [1]",
1457
+ "# [1, 2, 2]",
1458
+ "; [[3], [4, 5]] | [1, 2]",
1459
+ "# [1, 2, [3], [4, 5]]",
1460
+ "; .flop {(_ .1) | (_ .0)};",
1461
+ "; flop [[1, 2], [3, 4]]",
1462
+ "# [1, 2, 3, 4]",
1463
+ "```",
1464
+ "",
1465
+ "This also pins the direction: the second collection is traversed,",
1466
+ "while the first collection supplies the initial receiver. Empty",
1467
+ "inputs and repeated occurrences retain their usual Apply semantics.",
1468
+ "",
1469
+ "## Open design boundary",
1470
+ "",
1471
+ "Zip against an empty right-hand source is intentionally not asserted: absent",
1472
+ "addresses require a policy (truncate, refuse or propagate a missing value),",
1473
+ "which is also unresolved for other unequal lengths. A general element-only Zip",
1474
+ "must additionally decide whether to filter the property plane. Those policies",
1475
+ "require separate tests.",
1476
+ "",
1477
+ "```",
1478
+ "",
1479
+ ].join("\n"),
1480
+ ],
1481
+ [
1482
+ "hc/cd-bit-kernel.hc",
1483
+ [
1484
+ "#!/usr/bin/env hc",
1485
+ "```",
1486
+ "BitScheme sign-kernel experiment (Explore 023.05)",
1487
+ "",
1488
+ "This executable testdoc builds a paired-bit observation stream from nonnegative",
1489
+ "integer basis indices and descending powers of two. A pure mapping creates",
1490
+ "observations; an ordinary HC Frame with apply_ folds them into a Cayley–Dickson",
1491
+ "sign parity. It needs no new parser syntax and deliberately leaves the existing",
1492
+ "BitScheme schema matcher pure.",
1493
+ "",
1494
+ "The input powers must be a complete descending list [2^(n-1), ..., 1] and both",
1495
+ "indices must be in [0, 2^n). The example supplies explicit width-3 and width-8",
1496
+ "power lists. This is a bounded basis-sign testdoc, not a U64/bit-blob native API.",
1497
+ "The output 0 or 1 is the exponent of (-1), NOT a zero algebra coefficient.",
1498
+ "The doubling convention is (a,b)(c,d) = (ac - d* b, da + b c*).",
1499
+ "```",
1500
+ "```",
1501
+ "Bit observation: bit(x,p) uses modulo rather than a newly invented HC bitwise",
1502
+ "operator. p is a power of two and the input is a nonnegative integer.",
1503
+ "```",
1504
+ "; .cd_bit {.args _; .x (args .0); .p (args .1); ((x %% (2 * p)) .>= p) ? {1} : {0}};",
1505
+ "; .cd_bool {_ ? {1} : {0}};",
1506
+ "; cd_bit [5, 4]",
1507
+ "# 1",
1508
+ "; cd_bit [5, 2]",
1509
+ "# 0",
1510
+ "; cd_bit [5, 1]",
1511
+ "# 1",
1512
+ "```",
1513
+ "The observation map is pure:",
1514
+ "[u_bit, v_bit, lower_u_nonzero, lower_v_nonzero], from high to low.",
1515
+ "The lower-tail predicates refer to the",
1516
+ "original operands. The transition applies the current swapped orientation",
1517
+ "before interpreting each observation. Values below bit k are x %% 2^k.",
1518
+ "```",
1519
+ "; .cd_observe {",
1520
+ " .args _;",
1521
+ " .u (args .0);",
1522
+ " .v (args .1);",
1523
+ " .powers (args .2);",
1524
+ " powers & {.p _;",
1525
+ " [cd_bit [u, p], cd_bit [v, p], cd_bool ((u %% p) .> 0), cd_bool ((v %% p) .> 0)]}",
1526
+ "};",
1527
+ "; cd_observe [5, 3, [4, 2, 1]]",
1528
+ "# [[1, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 0]]",
1529
+ "```",
1530
+ "The accumulator has three visible state bits: parity, swapped, halted.",
1531
+ "Its apply_ rule consumes one observation and returns the same receiver for",
1532
+ "the next fold step. Once halted, further steps are observationally inert;",
1533
+ "this models early return without claiming native short-circuit iteration.",
1534
+ "",
1535
+ "Guard order is explicit. On 01: stop iff current u has no lower bits, else",
1536
+ "toggle orientation. On 10: stop iff current v has no lower bits, else flip",
1537
+ "parity. On 11: flip and stop iff current v has no lower bits, else toggle",
1538
+ "orientation. On 00: pass. All state changes are explicit alias assignments.",
1539
+ "Each conditional branch returns <> so a nil branch result cannot fall through.",
1540
+ "```",
1541
+ "; .CdSignState {",
1542
+ " [.parity 0; .swapped 0; .halted 0;",
1543
+ " .apply_ {",
1544
+ " .obs _;",
1545
+ " (halted = 0) ? {",
1546
+ " .a ((swapped = 0) ? {obs .0} : {obs .1});",
1547
+ " .b ((swapped = 0) ? {obs .1} : {obs .0});",
1548
+ " .alow ((swapped = 0) ? {obs .2} : {obs .3});",
1549
+ " .blow ((swapped = 0) ? {obs .3} : {obs .2});",
1550
+ " (a = 0) ? {",
1551
+ " (b = 1) ? {",
1552
+ " (alow = 0) ? {@halted 1; <>} : {@swapped (1 - swapped); <>}",
1553
+ " } : {<>}",
1554
+ " } : {",
1555
+ " (b = 0) ? {",
1556
+ " (blow = 0) ? {@halted 1; <>} : {@parity (1 - parity); <>}",
1557
+ " } : {",
1558
+ " (blow = 0) ? {@parity (1 - parity); @halted 1; <>} : {",
1559
+ " @swapped (1 - swapped); <>",
1560
+ " }",
1561
+ " }",
1562
+ " };",
1563
+ " <>",
1564
+ " } : {<>}",
1565
+ " }]",
1566
+ "};",
1567
+ "```",
1568
+ "A separate wrapper preserves the Rust reference's u=0 or v=0 return-0",
1569
+ "convention (basis index zero is the identity, not an algebraic zero).",
1570
+ "A fixed full-width scan is equivalent to starting at msb(u|v) because",
1571
+ "leading 00 observations leave the state unchanged.",
1572
+ "```",
1573
+ "; .cd_sign {",
1574
+ " .args _;",
1575
+ " .u (args .0);",
1576
+ " .v (args .1);",
1577
+ " .powers (args .2);",
1578
+ " (u = 0) ? {0} : {",
1579
+ " (v = 0) ? {0} : {",
1580
+ " (cd_observe [u, v, powers] | (CdSignState ())).parity",
1581
+ " }",
1582
+ " }",
1583
+ "};",
1584
+ "; cd_sign [0, 7, [4, 2, 1]]",
1585
+ "# 0",
1586
+ "; cd_sign [7, 0, [4, 2, 1]]",
1587
+ "# 0",
1588
+ "; cd_sign [1, 1, [4, 2, 1]]",
1589
+ "# 1",
1590
+ "; cd_sign [1, 2, [4, 2, 1]]",
1591
+ "# 0",
1592
+ "; cd_sign [2, 1, [4, 2, 1]]",
1593
+ "# 1",
1594
+ "; cd_sign [4, 2, [4, 2, 1]]",
1595
+ "# 1",
1596
+ "; cd_sign [2, 3, [4, 2, 1]]",
1597
+ "# 0",
1598
+ "; cd_sign [5, 3, [4, 2, 1]]",
1599
+ "# 0",
1600
+ "```",
1601
+ "Executable witnesses for the conventional Cayley–Dickson ladder.",
1602
+ "These are basis-product SIGN tests, not construction of the number carriers.",
1603
+ "For basis units e_u and e_v, the product index is u XOR v and this kernel",
1604
+ "supplies the coefficient (-1)^parity. The same cd_sign implementation is",
1605
+ "used at every rank; only the complete descending powers list changes.",
1606
+ "",
1607
+ "Real (rank 0): e_0 is the multiplicative identity. An empty scan is valid",
1608
+ "for its sole basis index; the identity wrapper returns parity 0.",
1609
+ "```",
1610
+ "; cd_sign [0, 0, []]",
1611
+ "# 0",
1612
+ "```",
1613
+ "Complex (rank 1): e_1 squared is -e_0.",
1614
+ "```",
1615
+ "; cd_sign [1, 1, [1]]",
1616
+ "# 1",
1617
+ "```",
1618
+ "Quaternion (rank 2): e_1 e_2 = +e_3 and e_2 e_1 = -e_3.",
1619
+ "This demonstrates anticommutation without a rank-specific kernel.",
1620
+ "```",
1621
+ "; cd_sign [1, 2, [2, 1]]",
1622
+ "# 0",
1623
+ "; cd_sign [2, 1, [2, 1]]",
1624
+ "# 1",
1625
+ "```",
1626
+ "Octonion (rank 3): a newly introduced unit e_4 squares to -e_0,",
1627
+ "and anticommutes with the earlier unit e_1.",
1628
+ "```",
1629
+ "; cd_sign [4, 4, [4, 2, 1]]",
1630
+ "# 1",
1631
+ "; cd_sign [1, 4, [4, 2, 1]]",
1632
+ "# 0",
1633
+ "; cd_sign [4, 1, [4, 2, 1]]",
1634
+ "# 1",
1635
+ "```",
1636
+ "Sedenion (rank 4): the new e_8 also squares to -e_0.",
1637
+ "The quaternion signs embed unchanged when a leading zero bit is added.",
1638
+ "```",
1639
+ "; cd_sign [8, 8, [8, 4, 2, 1]]",
1640
+ "# 1",
1641
+ "; cd_sign [1, 2, [8, 4, 2, 1]]",
1642
+ "# 0",
1643
+ "; cd_sign [2, 1, [8, 4, 2, 1]]",
1644
+ "# 1",
1645
+ "```",
1646
+ "Rank 5 (32 dimensions): e_16 squares to -e_0 and the same",
1647
+ "quaternion signs persist through another doubling.",
1648
+ "```",
1649
+ "; cd_sign [16, 16, [16, 8, 4, 2, 1]]",
1650
+ "# 1",
1651
+ "; cd_sign [1, 2, [16, 8, 4, 2, 1]]",
1652
+ "# 0",
1653
+ "; cd_sign [2, 1, [16, 8, 4, 2, 1]]",
1654
+ "# 1",
1655
+ "```",
1656
+ "These witnesses demonstrate sign behavior and lower-rank embedding.",
1657
+ "They do not by themselves prove nonassociativity, zero divisors,",
1658
+ "or the emergence of negative integers from counting numbers.",
1659
+ "```",
1660
+ "```",
1661
+ "Cayley–Dickson ladder: a few executable witnesses, one sign kernel.",
1662
+ "",
1663
+ "For basis units e_u e_v = (-1)^parity e_(u XOR v), these assertions check",
1664
+ "the coefficient sign only; the basis-index XOR is a mathematical convention,",
1665
+ "not an operation implemented by this kernel. The full algebra of linear",
1666
+ "combinations is deliberately out of scope. All ranks use the same cd_sign.",
1667
+ "",
1668
+ "Rank 0, real: e_0 is the identity (parity 0).",
1669
+ "Rank 1, complex: e_1 squared is -e_0 (parity 1).",
1670
+ "Rank 2, quaternion: e_1 e_2 = +e_3 and e_2 e_1 = -e_3.",
1671
+ "```",
1672
+ "; cd_sign [0, 0, [1]]",
1673
+ "# 0",
1674
+ "; cd_sign [0, 1, [1]]",
1675
+ "# 0",
1676
+ "; cd_sign [1, 1, [1]]",
1677
+ "# 1",
1678
+ "; cd_sign [1, 2, [2, 1]]",
1679
+ "# 0",
1680
+ "; cd_sign [2, 1, [2, 1]]",
1681
+ "# 1",
1682
+ "; cd_sign [3, 3, [2, 1]]",
1683
+ "# 1",
1684
+ "```",
1685
+ "Rank 3, octonion: e_1, e_2, e_4 give a nonassociative witness.",
1686
+ "(e_1 e_2) e_4 has sign 0; e_1 (e_2 e_4) has sign 1.",
1687
+ "The products have the same final basis index 7, but opposite signs.",
1688
+ "We compute each composite sign from two calls to the same kernel.",
1689
+ "```",
1690
+ "; cd_sign [1, 2, [4, 2, 1]]",
1691
+ "# 0",
1692
+ "; cd_sign [3, 4, [4, 2, 1]]",
1693
+ "# 0",
1694
+ "; cd_sign [2, 4, [4, 2, 1]]",
1695
+ "# 0",
1696
+ "; cd_sign [1, 6, [4, 2, 1]]",
1697
+ "# 1",
1698
+ "; ((cd_sign [1, 2, [4, 2, 1]]) + (cd_sign [3, 4, [4, 2, 1]])) %% 2",
1699
+ "# 0",
1700
+ "; ((cd_sign [2, 4, [4, 2, 1]]) + (cd_sign [1, 6, [4, 2, 1]])) %% 2",
1701
+ "# 1",
1702
+ "```",
1703
+ "Rank 4, sedenion: e_8 squared is -e_0, and its products with",
1704
+ "the existing quaternion generator are orientation-sensitive.",
1705
+ "The embedded quaternion product e_1 e_2 retains its sign.",
1706
+ "Rank 5: a new e_16 also squares to -e_0; the embedded e_1 e_2",
1707
+ "still has the same sign. No zero-divisor claim follows from signs alone.",
1708
+ "```",
1709
+ "; cd_sign [8, 8, [8, 4, 2, 1]]",
1710
+ "# 1",
1711
+ "; cd_sign [8, 1, [8, 4, 2, 1]]",
1712
+ "# 1",
1713
+ "; cd_sign [1, 8, [8, 4, 2, 1]]",
1714
+ "# 0",
1715
+ "; cd_sign [1, 2, [8, 4, 2, 1]]",
1716
+ "# 0",
1717
+ "; cd_sign [16, 16, [16, 8, 4, 2, 1]]",
1718
+ "# 1",
1719
+ "; cd_sign [1, 2, [16, 8, 4, 2, 1]]",
1720
+ "# 0",
1721
+ "```",
1722
+ "Flat counting-number coordinates, before signed-coefficient flattening.",
1723
+ "",
1724
+ "ONE number is a FLAT list of nonnegative counting magnitudes. For a",
1725
+ "Cayley-Dickson rung with m basis directions, its signed presentation has",
1726
+ "2m counting slots in the order",
1727
+ "",
1728
+ " [positive e0, ..., positive e(m-1),",
1729
+ " negative e0, ..., negative e(m-1)].",
1730
+ "",
1731
+ "The second half is not another number or another basis dimension. It is",
1732
+ "the opposite orientation for the SAME m basis directions. For the complex",
1733
+ "rung one number has four counts [a,b,c,d]; its eventual algebraic",
1734
+ "observation is (a-c) + (b-d)i. No signed literals, quotient classes or",
1735
+ "nested signed-coefficient pairs occur as primitive HC inputs here.",
1736
+ "",
1737
+ "The observational gauge identifies two equal-length flat lists x,y iff",
1738
+ "for EVERY basis position j in [0,m), x[j]+y[j+m]=x[j+m]+y[j].",
1739
+ "The quotient interprets the flat states as signed coefficients; the",
1740
+ "states themselves are retained, not silently normalized.",
1741
+ "",
1742
+ "HC's doubled-map addresses are symbolic, NOT numeric indices. Instead",
1743
+ "the following ordinary fold class splits a flat stream after m slots,",
1744
+ "without treating those addresses as arithmetic. This same split",
1745
+ "implements the n/2 half-rotation after zero-padding to a chosen CD arity.",
1746
+ "```",
1747
+ "; .CdFlatSplit {",
1748
+ " [.half _;",
1749
+ " .i 0;",
1750
+ " .front [];",
1751
+ " .back [];",
1752
+ " .apply_ {",
1753
+ " .v _;",
1754
+ " (i .< half) ? {@front (front v); <>} : {@back (back v); <>};",
1755
+ " @i (i + 1);",
1756
+ " _^^",
1757
+ " }]",
1758
+ "};",
1759
+ "; .cd_flat_neg {",
1760
+ " .x _;",
1761
+ " .half (((x.#) / 2).##);",
1762
+ " .split (x | (CdFlatSplit half));",
1763
+ " (split.front) | (split.back)",
1764
+ "};",
1765
+ "```",
1766
+ "A sign reversal is ONLY a half-rotation of a valid, flat,",
1767
+ "2m-slot CD presentation: at n=2 it swaps two counts; at n=4 it rotates",
1768
+ "four counts by two slots; at n=8 it rotates eight by four. It neither",
1769
+ "calls an integer minus nor introduces a new algebraic operation.",
1770
+ "",
1771
+ "To lift the value to the NEXT CD rung, insert m zeros after EACH",
1772
+ "m-slot half separately. This halfwise padding COMMUTES with the n/2",
1773
+ "rotation. Appending zeros only at the end would move the positive/negative",
1774
+ "boundary and CHANGE the value.",
1775
+ "",
1776
+ "Both halves are taken from the SAME flat value and padded separately.",
1777
+ "This preserves the old CD basis directions in the higher rung. The",
1778
+ "doubling length is already specified by the source CD arity; no signed",
1779
+ "literals, arbitrary-list zero-fill, or automatic size inference.",
1780
+ "```",
1781
+ "; .cd_flat_embed_cd {",
1782
+ " .x _;",
1783
+ " .half (((x.#) / 2).##);",
1784
+ " .parts (x | (CdFlatSplit half));",
1785
+ " .zeros ((parts.front) & {0});",
1786
+ " .positive (zeros | (parts.front));",
1787
+ " .negative (zeros | (parts.back));",
1788
+ " negative | positive",
1789
+ "};",
1790
+ "; cd_flat_embed_cd [3, 1]",
1791
+ "# [3, 0, 1, 0]",
1792
+ "; cd_flat_embed_cd [3, 4, 1, 2]",
1793
+ "# [3, 4, 0, 0, 1, 2, 0, 0]",
1794
+ "; cd_flat_neg [3, 1]",
1795
+ "# [1, 3]",
1796
+ "; cd_flat_neg [3, 4, 1, 0]",
1797
+ "# [1, 0, 3, 4]",
1798
+ "; cd_flat_neg [1, 2, 3, 4, 5, 6, 7, 8]",
1799
+ "# [5, 6, 7, 8, 1, 2, 3, 4]",
1800
+ "; cd_flat_neg (cd_flat_neg [3, 4, 1, 0])",
1801
+ "# [3, 4, 1, 0]",
1802
+ "; cd_flat_neg (cd_flat_embed_cd [3, 1])",
1803
+ "# [1, 0, 3, 0]",
1804
+ "; cd_flat_embed_cd (cd_flat_neg [3, 1])",
1805
+ "# [1, 0, 3, 0]",
1806
+ "```",
1807
+ "Addition is slotwise counting-number addition (native Zip). The add/mul",
1808
+ "helpers assume equal-width CD operands at the stated rung; native Zip",
1809
+ "truncates unequal lists. Equality must explicitly reject unequal widths.",
1810
+ "Within one rung, gauge equality is checked without subtraction: x and y",
1811
+ "are equivalent exactly when x plus the half-rotation of y has equal",
1812
+ "positive and negative halves. Both addends and the result remain flat.",
1813
+ "```",
1814
+ "; .cd_flat_add {",
1815
+ " .xy _;",
1816
+ " ((xy .0) |&| (xy .1)) & {((_ .0) + (_ .1))}",
1817
+ "};",
1818
+ "; .cd_flat_eq {",
1819
+ " .xy _;",
1820
+ " .diff (cd_flat_add [(xy .0), cd_flat_neg (xy .1)]);",
1821
+ " .half (((diff.#) / 2).##);",
1822
+ " .split (diff | (CdFlatSplit half));",
1823
+ " (((xy .0).#) = ((xy .1).#)) ? {cd_bool ((split.front) = (split.back))} : {0}",
1824
+ "};",
1825
+ "; cd_flat_eq [[3, 4, 1, 2], [4, 5, 2, 3]]",
1826
+ "# 1",
1827
+ "; cd_flat_eq [cd_flat_embed_cd [3, 1], [2, 0, 0, 0]]",
1828
+ "# 1",
1829
+ "; cd_flat_eq [cd_flat_embed_cd [4, 2], cd_flat_embed_cd [3, 1]]",
1830
+ "# 1",
1831
+ "; cd_flat_eq [[3, 4, 1, 2], [3, 4, 1, 3]]",
1832
+ "# 0",
1833
+ "; cd_flat_eq [[3, 1, 0, 0], [2, 0]]",
1834
+ "# 0",
1835
+ "; cd_flat_eq [[2, 0], [3, 1, 0, 0]]",
1836
+ "# 0",
1837
+ "; cd_flat_eq [cd_flat_neg [3, 4, 1, 2], [2, 3, 4, 5]]",
1838
+ "# 1",
1839
+ "; cd_flat_add [[3, 4, 1, 2], cd_flat_neg [3, 4, 1, 2]]",
1840
+ "# [4, 6, 4, 6]",
1841
+ "; cd_flat_eq [cd_flat_add [[3, 4, 1, 2], cd_flat_neg [3, 4, 1, 2]], [0, 0, 0, 0]]",
1842
+ "# 1",
1843
+ "```",
1844
+ "Product generation from the SAME cd_sign rule.",
1845
+ "",
1846
+ "The input stream's slot order already determines the CD basis index",
1847
+ "(slot modulo half) and its sign orientation. Native Cart forms all",
1848
+ "input-slot pairs; each contributes its magnitude product to the output",
1849
+ "basis index u XOR v, with sign = both input orientations XOR cd_sign.",
1850
+ "The transient [magnitude,basis index,orientation] routing records are",
1851
+ "NOT nested signed coefficients.",
1852
+ "",
1853
+ "cd_flat_xor uses the same observed bits as cd_sign, with no added",
1854
+ "bitwise-language primitive. Powers [] is the real, rank-zero case.",
1855
+ "```",
1856
+ "; .cd_flat_xor {",
1857
+ " .args _;",
1858
+ " .u (args .0);",
1859
+ " .v (args .1);",
1860
+ " .powers (args .2);",
1861
+ " (powers.# = 0) ? {0} : {",
1862
+ " (powers & {.p _; (((cd_bit [u, p]) + (cd_bit [v, p])) %% 2) * p}).##",
1863
+ " }",
1864
+ "};",
1865
+ "; cd_flat_xor [1, 2, [2, 1]]",
1866
+ "# 3",
1867
+ "; cd_flat_xor [3, 3, [2, 1]]",
1868
+ "# 0",
1869
+ "; .CdFlatSlotter {",
1870
+ " [.half _;",
1871
+ " .i 0;",
1872
+ " .slots [];",
1873
+ " .apply_ {",
1874
+ " .magnitude _;",
1875
+ " .basis (i %% half);",
1876
+ " .orientation ((i .< half) ? {0} : {1});",
1877
+ " @slots (slots [magnitude, basis, orientation]);",
1878
+ " @i (i + 1);",
1879
+ " _^^",
1880
+ " }]",
1881
+ "};",
1882
+ "; .cd_flat_term {",
1883
+ " .args _;",
1884
+ " .ab (args .0);",
1885
+ " .powers (args .1);",
1886
+ " .half (args .2);",
1887
+ " .a (ab .0);",
1888
+ " .b (ab .1);",
1889
+ " .u (a .1);",
1890
+ " .v (b .1);",
1891
+ " .mag ((a .0) * (b .0));",
1892
+ " .parity ((((a .2) + (b .2)) + (cd_sign [u, v, powers])) %% 2);",
1893
+ " [mag, ((cd_flat_xor [u, v, powers]) + (half * parity))]",
1894
+ "};",
1895
+ "; .CdFlatDeposit {",
1896
+ " [.dest (_ .0);",
1897
+ " .mag (_ .1);",
1898
+ " .i 0;",
1899
+ " .out [];",
1900
+ " .apply_ {",
1901
+ " .v _;",
1902
+ " @out (out (v + ((i = dest) ? {mag} : {0})));",
1903
+ " @i (i + 1);",
1904
+ " _^^",
1905
+ " }]",
1906
+ "};",
1907
+ "; .CdFlatCollector {",
1908
+ " [.counts _;",
1909
+ " .apply_ {",
1910
+ " .term _;",
1911
+ " .mag (term .0);",
1912
+ " .dest (term .1);",
1913
+ " @counts ((counts | (CdFlatDeposit [dest, mag])).out);",
1914
+ " _^^",
1915
+ " }]",
1916
+ "};",
1917
+ "; .cd_flat_mul {",
1918
+ " .args _;",
1919
+ " .x (args .0);",
1920
+ " .y (args .1);",
1921
+ " .powers (args .2);",
1922
+ " .half (((x.#) / 2).##);",
1923
+ " .xs (x | (CdFlatSlotter half));",
1924
+ " .ys (y | (CdFlatSlotter half));",
1925
+ " .terms (((xs.slots) &|& (ys.slots)) & {cd_flat_term [_, powers, half]});",
1926
+ " (terms | (CdFlatCollector (x & {0}))).counts",
1927
+ "};",
1928
+ "```",
1929
+ "Real (one CD basis direction; two counting slots), complex (two basis",
1930
+ "directions; four slots), and quaternion (four basis directions; eight",
1931
+ "slots) reuse this SINGLE flat sign/multiply/rotation construction.",
1932
+ "```",
1933
+ "; cd_flat_mul [[0, 1], [0, 1], []]",
1934
+ "# [1, 0]",
1935
+ "; cd_flat_mul [[0, 1, 0, 0], [0, 1, 0, 0], [1]]",
1936
+ "# [0, 0, 1, 0]",
1937
+ "; cd_flat_mul [[0, 1, 0, 0], [1, 0, 0, 0], [1]]",
1938
+ "# [0, 1, 0, 0]",
1939
+ "; cd_flat_eq [cd_flat_mul [[2, 0, 1, 0], [0, 3, 0, 2], [1]], [0, 1, 0, 0]]",
1940
+ "# 1",
1941
+ "; cd_flat_eq [cd_flat_mul [cd_flat_neg [0, 1, 0, 0], cd_flat_neg [0, 1, 0, 0], [1]], [0, 0, 1, 0]]",
1942
+ "# 1",
1943
+ "; cd_flat_mul [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [2, 1]]",
1944
+ "# [0, 0, 0, 1, 0, 0, 0, 0]",
1945
+ "; cd_flat_mul [[0, 0, 1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [2, 1]]",
1946
+ "# [0, 0, 0, 0, 0, 0, 0, 1]",
1947
+ "```",
1948
+ "Embedding into the next CD rung preserves multiplication modulo gauge:",
1949
+ "`embed(x*y) ~ embed(x)*embed(y)`. This tests the higher-rung basis",
1950
+ "compatibility directly, not just the coordinate layout.",
1951
+ "```",
1952
+ "; cd_flat_eq [cd_flat_embed_cd (cd_flat_mul [[2, 0, 1, 0], [0, 3, 0, 2], [1]]), cd_flat_mul [cd_flat_embed_cd [2, 0, 1, 0], cd_flat_embed_cd [0, 3, 0, 2], [2, 1]]]",
1953
+ "# 1",
1954
+ "```",
1955
+ "Scope and interpretation:",
1956
+ "",
1957
+ "One flat list gives ONE signed CD value on the selected rung.",
1958
+ "Its n/2 rotation is a concrete permutation of the padded counting slots;",
1959
+ "the gauge quotient is a later observational flattening, not an input",
1960
+ "assumption. The same cd_sign kernel governs the destination-half choice",
1961
+ "for every basis product, while cd_flat_xor routes to a CD basis direction.",
1962
+ "",
1963
+ "The witnesses use real/complex/quaternion powers and do not claim a",
1964
+ "new HCLang general-Frame unary Permute, the full FOIST Denumeration",
1965
+ "semantics, automatic arbitrary-width CD arity selection, or a theorem",
1966
+ "that cd_sign alone constructs the gauge quotient.",
1967
+ "```",
1968
+ "```",
1969
+ "Complete 8-by-8 octonion basis-sign matrix at width 3. Expected data were",
1970
+ "computed independently from the Rust reference in Explore 023.01. This",
1971
+ "exercises all four current-bit cases and orientation/early-stop paths.",
1972
+ "```",
1973
+ "; .cd_oct [0, 1, 2, 3, 4, 5, 6, 7];",
1974
+ "; cd_oct & {.left _; cd_oct & {cd_sign [left, _, [4, 2, 1]]}}",
1975
+ "# [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 1, 0], [0, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 0, 1, 0, 1], [0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 1, 0, 1, 1, 1, 0], [0, 0, 0, 1, 1, 0, 1, 1], [0, 1, 0, 0, 1, 1, 0, 1]]",
1976
+ "```",
1977
+ "Bit 7 and leading-zero coverage with an explicit 8-bit scan. No U64 shift",
1978
+ "coercions or JavaScript bitwise truncation are involved in the HC arithmetic.",
1979
+ "```",
1980
+ "; .cd_sign8 {cd_sign [(_ .0), (_ .1), [128, 64, 32, 16, 8, 4, 2, 1]]};",
1981
+ "; cd_sign8 [128, 128]",
1982
+ "# 1",
1983
+ "; cd_sign8 [128, 1]",
1984
+ "# 1",
1985
+ "; cd_sign8 [128, 129]",
1986
+ "# 0",
1987
+ "; cd_sign8 [255, 255]",
1988
+ "# 1",
1989
+ "; cd_sign8 [255, 127]",
1990
+ "# 0",
1991
+ "```",
1992
+ "The fold implements CD sign parity over numeric basis indices.",
1993
+ "It is not new BitScheme syntax, a generalized signature kernel,",
1994
+ "or a proof about the physical geometry of the indexing space.",
1995
+ "```",
1996
+ "",
1997
+ "```",
1998
+ "The BitScheme matcher also serves as a pure ingress adapter. This fixed-width schema captures eight individual bits without",
1999
+ "changing its input. A separate ordinary HC computation converts the evidence",
2000
+ "to the numeric index consumed by the scan; schema matching stays read-only.",
2001
+ "This is an 8-bit bridge, NOT a public two-blob cursor or an implicit cast.",
2002
+ "```",
2003
+ "; .CdByte <[",
2004
+ " .b7 <1@Bit>; .b6 <1@Bit>; .b5 <1@Bit>; .b4 <1@Bit>;",
2005
+ " .b3 <1@Bit>; .b2 <1@Bit>; .b1 <1@Bit>; .b0 <1@Bit>;",
2006
+ "]>;",
2007
+ "; .cd_byte_index {",
2008
+ " .bits (CdByte _);",
2009
+ " .w76 (((cd_bool (bits.b7 = 0b1)) * 128) + ((cd_bool (bits.b6 = 0b1)) * 64));",
2010
+ " .w54 (((cd_bool (bits.b5 = 0b1)) * 32) + ((cd_bool (bits.b4 = 0b1)) * 16));",
2011
+ " .w32 (((cd_bool (bits.b3 = 0b1)) * 8) + ((cd_bool (bits.b2 = 0b1)) * 4));",
2012
+ " .w10 (((cd_bool (bits.b1 = 0b1)) * 2) + (cd_bool (bits.b0 = 0b1)));",
2013
+ " w76 + w54 + w32 + w10",
2014
+ "};",
2015
+ "; cd_byte_index 0b10100101",
2016
+ "# 165",
2017
+ "; cd_byte_index 0b00000000",
2018
+ "# 0",
2019
+ "; .cd_sign_bits8 {.inputs _; cd_sign8 [cd_byte_index (inputs .0), cd_byte_index (inputs .1)]};",
2020
+ "; cd_sign_bits8 [0b10000000, 0b10000001]",
2021
+ "# 0",
2022
+ "; cd_sign_bits8 [0b10000000, 0b00000001]",
2023
+ "# 1",
2024
+ "; cd_sign_bits8 [0b10000000, 0b00000000]",
2025
+ "# 0",
2026
+ "; cd_sign_bits8 [0b00000010, 0b00000001]",
2027
+ "# 1",
2028
+ "; cd_sign_bits8 [0b00000101, 0b00000011]",
2029
+ "# 0",
2030
+ "",
2031
+ "```",
2032
+ "Negative ingress witnesses: schema matching rejects undersized,",
2033
+ "oversized, and non-binary input instead of implicitly coercing it.",
2034
+ "```",
2035
+ "; cd_byte_index 0b101",
2036
+ "# $!.insufficient-bits .b4 3",
2037
+ "; cd_byte_index 0b111111111",
2038
+ "# $!.unconsumed-bits 1",
2039
+ "; cd_byte_index 5",
2040
+ "# $!.bit-input-invalid 5",
2041
+ "```",
2042
+ "BitScheme ingress rejects incomplete, oversized, or non-blob inputs.",
2043
+ "These are executable error-contract witnesses, not new parser behavior.",
2044
+ "```",
2045
+ "; cd_byte_index 0b101",
2046
+ "# $!.insufficient-bits .b4 3",
2047
+ "; cd_byte_index 0b111111111",
2048
+ "# $!.unconsumed-bits 1",
2049
+ "; cd_byte_index 5",
2050
+ "# $!.bit-input-invalid 5",
2051
+ "",
2052
+ ].join("\n"),
2053
+ ],
1359
2054
  [
1360
2055
  "hc/class-support.hc",
1361
2056
  [
@@ -3794,6 +4489,99 @@ export const HC_SOURCES = new Map([
3794
4489
  "",
3795
4490
  ].join("\n"),
3796
4491
  ],
4492
+ [
4493
+ "hc/native-cart-zip.hc",
4494
+ [
4495
+ "#!/usr/bin/env hc",
4496
+ "```",
4497
+ "Native Cart &|& and Zip |&| — FOIST 15",
4498
+ "",
4499
+ "The former derived Cart and Zip design patterns are tested in cart-zip.hc.",
4500
+ "These operators pair immediate positional elements as values, without",
4501
+ "evaluating or descending into nested children. Cart enumerates a flat",
4502
+ "left-major product; Zip truncates to the shorter list. Named properties",
4503
+ "are excluded from the pairing domains.",
4504
+ "```",
4505
+ "",
4506
+ "```",
4507
+ "Cart: left-major, flat Cartesian pairing.",
4508
+ "```",
4509
+ "; [1, 2] &|& [10, 20, 30]",
4510
+ "# [[1, 10], [1, 20], [1, 30], [2, 10], [2, 20], [2, 30]]",
4511
+ "; [1, 1] &|& [2, 2]",
4512
+ "# [[1, 2], [1, 2], [1, 2], [1, 2]]",
4513
+ "; [] &|& [10, 20]",
4514
+ "# []",
4515
+ "; [1, 2] &|& []",
4516
+ "# []",
4517
+ "; [[1], [2]] &|& [[3], [4]]",
4518
+ "# [[[1], [3]], [[1], [4]], [[2], [3]], [[2], [4]]]",
4519
+ "",
4520
+ "```",
4521
+ "Zip: equal inputs, unequal inputs, and empty inputs.",
4522
+ "```",
4523
+ "; [1, 2] |&| [10, 20]",
4524
+ "# [[1, 10], [2, 20]]",
4525
+ "; [1, 2] |&| [10, 20, 30]",
4526
+ "# [[1, 10], [2, 20]]",
4527
+ "; [1, 2, 3] |&| [10]",
4528
+ "# [[1, 10]]",
4529
+ "; [1, 2] |&| []",
4530
+ "# []",
4531
+ "; [] |&| [10, 20]",
4532
+ "# []",
4533
+ "; [1, 1] |&| [2, 2]",
4534
+ "# [[1, 2], [1, 2]]",
4535
+ "; [[1], [2]] |&| [[3]]",
4536
+ "# [[[1], [3]]]",
4537
+ "",
4538
+ "```",
4539
+ "Named properties are not positional elements, on either side.",
4540
+ "```",
4541
+ "; [.meta 9; 1, 2] |&| [.tag 8; 10, 20, 30]",
4542
+ "# [[1, 10], [2, 20]]",
4543
+ "; [.meta 9; 1, 2] &|& [.tag 8; 10]",
4544
+ "# [[1, 10], [2, 10]]",
4545
+ "",
4546
+ "```",
4547
+ "Native operations agree with the derived patterns on their shared domain.",
4548
+ "The derived Zip still has its own property and missing-address semantics.",
4549
+ "```",
4550
+ "; .A [1, 2];",
4551
+ "; .B [10, 20];",
4552
+ "; A &|& B",
4553
+ "# [[1, 10], [1, 20], [2, 10], [2, 20]]",
4554
+ "; A &| {.a _; B & {[a, _]}}",
4555
+ "# [[1, 10], [1, 20], [2, 10], [2, 20]]",
4556
+ "; A |&| B",
4557
+ "# [[1, 10], [2, 20]]",
4558
+ "; A && {[_.1, B (_.0)]}",
4559
+ "# [[1, 10], [2, 20]]",
4560
+ "",
4561
+ "```",
4562
+ "Operand shape follows HC's existing element iteration convention:",
4563
+ "a scalar or nil is one element; property-only Frames have no elements.",
4564
+ "Chaining pairs left to right instead of flattening triples.",
4565
+ "```",
4566
+ "; () |&| [1]",
4567
+ "# [[(), 1]]",
4568
+ "; 1 &|& [2, 3]",
4569
+ "# [[1, 2], [1, 3]]",
4570
+ "; “ab” |&| [1, 2]",
4571
+ "# [[“ab”, 1]]",
4572
+ "; (.a 1, .b 2) |&| [3, 4]",
4573
+ "# []",
4574
+ "; [1, 2] |&| [3, 4] |&| [5, 6]",
4575
+ "# [[[1, 3], 5], [[2, 4], 6]]",
4576
+ "",
4577
+ "```",
4578
+ "Closure elements are source-code atoms, not evaluated closure results.",
4579
+ "```",
4580
+ "; [1] &|& {_ + 1}",
4581
+ "# [[1, _], [1, +], [1, 1]]",
4582
+ "",
4583
+ ].join("\n"),
4584
+ ],
3797
4585
  [
3798
4586
  "hc/numerics.hc",
3799
4587
  [
@@ -0,0 +1,35 @@
1
+ import { FrameArray } from "../frames/frame-array.js";
2
+ /**
3
+ * Native Cart: flat, left-major Cartesian pairing of immediate elements.
4
+ *
5
+ * Like HC's other element iterators, this reads the positional element plane;
6
+ * named properties are not inputs. Repeated occurrences remain repeated.
7
+ * Pairing is structural: each result is a two-element Frame, and neither
8
+ * operand is evaluated, modified, or recursively traversed. As with `&`,
9
+ * scalars are singleton elements and closures expose their source-code atoms.
10
+ */
11
+ export const CartElements = (left, right) => {
12
+ const pairs = [];
13
+ const rightElements = right.elements();
14
+ for (const a of left.elements()) {
15
+ for (const b of rightElements) {
16
+ pairs.push(new FrameArray([a, b]));
17
+ }
18
+ }
19
+ return new FrameArray(pairs);
20
+ };
21
+ /**
22
+ * Native Zip: pair positional elements in lockstep, truncating to the shorter
23
+ * input. An operand with no positional elements returns an empty Frame;
24
+ * scalars remain singleton elements. Named properties are excluded.
25
+ */
26
+ export const ZipElements = (left, right) => {
27
+ const leftElements = left.elements();
28
+ const rightElements = right.elements();
29
+ const count = Math.min(leftElements.length, rightElements.length);
30
+ const pairs = [];
31
+ for (let i = 0; i < count; i++) {
32
+ pairs.push(new FrameArray([leftElements[i], rightElements[i]]));
33
+ }
34
+ return new FrameArray(pairs);
35
+ };
package/esm/lib/ops.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IfElse, IfThen } from "./ops/conditionals.js";
2
+ import { CartElements, ZipElements } from "./ops/pairings.js";
2
3
  import { FrameOps } from "./ops/frame-ops.js";
3
4
  import { MapElements, MapMembers, ReduceElements, ReduceMembers, SpliceElements, } from "./ops/iterators.js";
4
5
  import { Add, Divide, Equals, GreaterThan, GreaterThanOrEqual, Identical, LessThan, LessThanOrEqual, Modulo, Multiply, Power, Subtract, TypeEquals, } from "./ops/math.js";
@@ -9,6 +10,8 @@ export const Ops = new FrameOps({
9
10
  "&": MapElements,
10
11
  "&&": MapMembers,
11
12
  "&|": SpliceElements,
13
+ "&|&": CartElements,
14
+ "|&|": ZipElements,
12
15
  ":": IfElse,
13
16
  "?": IfThen,
14
17
  "|": ReduceElements,
@@ -1 +1 @@
1
- export const VERSION = "0.53.0";
1
+ export const VERSION = "0.53.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hclang",
3
- "version": "0.53.0",
3
+ "version": "0.53.1",
4
4
  "description": "Homoiconic C command-line interpreter and REPL",
5
5
  "keywords": [
6
6
  "language",