Skip to content

Commit ca6d85f

Browse files
committed
Fix apply with list args dispatching to wrong arity
knownSeqLength now handles .list (PersistentList) and .cons (cons chain) types, enabling apply to correctly dispatch to exact arities instead of always falling through to the variadic path. Fixes eduction (5 transducer test failures) where (apply comp (butlast xforms)) was calling comp's variadic arity instead of the single-arg arity, producing a non-functional transducer wrapper.
1 parent 0493b99 commit ca6d85f

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ a native implementation targeting behavioral compatibility with Clojure.
2424
- **Wasm FFI** — call WebAssembly modules from Clojure (523 opcodes including SIMD + GC)
2525
- **Dual backend** — bytecode VM (default) + TreeWalk interpreter (reference)
2626
- **deps.edn compatible** — Clojure CLI subset (-A/-M/-X/-P, git deps, local deps)
27-
- **1050+ vars** across 30+ namespaces (637/706 clojure.core)
27+
- **1100+ vars** across 30+ namespaces (651/706 clojure.core)
2828

2929
## Getting Started
3030

@@ -94,7 +94,7 @@ Known divergences are documented in [DIFFERENCES.md](DIFFERENCES.md).
9494

9595
| Namespace | Vars | Description |
9696
|------------------------|--------|--------------------------------------|
97-
| clojure.core | 637/706| Core language functions |
97+
| clojure.core | 651/706| Core language functions |
9898
| clojure.core.protocols | 10/11 | CollReduce, IKVReduce, Datafiable |
9999
| clojure.core.reducers | 22/22 | Parallel fold, monoid, reducers |
100100

@@ -107,7 +107,7 @@ Known divergences are documented in [DIFFERENCES.md](DIFFERENCES.md).
107107
| clojure.set | 12/12 | Set operations |
108108
| clojure.walk | 10/10 | Tree walking |
109109
| clojure.zip | 28/28 | Zipper data structure |
110-
| clojure.data | 3/5 | Data diff |
110+
| clojure.data | 5/5 | Data diff |
111111
| clojure.edn | 2/2 | EDN reader |
112112
| clojure.template | 2/2 | Code templates |
113113
| clojure.xml | 7/9 | XML parsing (pure Clojure) |
@@ -120,24 +120,25 @@ Known divergences are documented in [DIFFERENCES.md](DIFFERENCES.md).
120120
| Namespace | Vars | Description |
121121
|------------------------|--------|--------------------------------|
122122
| clojure.spec.alpha | 87/87 | Spec validation, s/def, s/valid?|
123-
| clojure.spec.gen.alpha | 27/54 | Spec generators |
123+
| clojure.spec.gen.alpha | 54/54 | Spec generators |
124+
| clojure.core.specs.alpha| 1/1 | Spec for core macros |
124125

125126
**Dev & Test**
126127

127128
| Namespace | Vars | Description |
128129
|--------------------|--------|--------------------------------|
129-
| clojure.test | 32/39 | Test framework |
130+
| clojure.test | 38/39 | Test framework |
130131
| clojure.test.tap | 7/7 | TAP output formatter |
131132
| clojure.repl | 11/13 | doc, dir, apropos, source, pst |
132-
| clojure.pprint | 9/26 | Pretty printing, print-table |
133+
| clojure.pprint | 22/26 | Pretty printing, print-table |
133134
| clojure.stacktrace | 6/6 | Stack trace utilities |
134135
| clojure.main | 16/20 | REPL, script loading, ex-triage|
135136

136137
**IO & System**
137138

138139
| Namespace | Vars | Description |
139140
|------------------------|--------|--------------------------------|
140-
| clojure.java.io | 7/19 | File I/O (Zig-native) |
141+
| clojure.java.io | 19/19 | File I/O (Zig-native) |
141142
| clojure.java.shell | 5/5 | Shell commands (sh) |
142143
| clojure.java.browse | 2/2 | Open URL in browser |
143144
| clojure.java.process | 5/9 | Process API (Clojure 1.12) |
@@ -146,7 +147,7 @@ Known divergences are documented in [DIFFERENCES.md](DIFFERENCES.md).
146147

147148
| Namespace | Vars | Description |
148149
|------------------------|--------|--------------------------------|
149-
| clojure.core.server | 7/11 | Socket REPL, prepl (stub) |
150+
| clojure.core.server | 7/11 | Socket REPL, prepl (partial) |
150151
| clojure.repl.deps | 3/3 | Dynamic lib addition (stub) |
151152

152153
**ClojureWasm Extensions**

src/builtins/collections.zig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,23 @@ fn knownSeqLength(val: Value) ?usize {
10651065
.set => val.asSet().count(),
10661066
.string => val.asString().len,
10671067
.nil => 0,
1068-
else => null, // cons, lazy_seq — can't know without realization
1068+
.list => val.asList().count(),
1069+
.cons => blk: {
1070+
// Walk cons chain to count (finite lists from butlast etc.)
1071+
var count: usize = 0;
1072+
var cur = val;
1073+
while (cur.tag() == .cons) {
1074+
count += 1;
1075+
cur = cur.asCons().rest;
1076+
if (count > 256) break :blk null; // safety limit
1077+
}
1078+
if (cur == Value.nil_val or cur.tag() == .list) {
1079+
if (cur.tag() == .list) count += cur.asList().count();
1080+
break :blk count;
1081+
}
1082+
break :blk null; // lazy tail
1083+
},
1084+
else => null, // lazy_seq — can't know without realization
10691085
};
10701086
}
10711087

0 commit comments

Comments
 (0)