Fix transpose closure capture bug (issue #11) - #12
Conversation
The inner lambda in transpose captured i from the outer closure by move, which Carp's borrow checker rejects—captured values must be borrowed (&) or copied (@&). Since lookup takes Index by value, use @&i to copy on each call. Also fix test-all.sh to propagate carp exit codes (set -euo pipefail) and quote the file path.
There was a problem hiding this comment.
Build & Tests
CI fails on both ubuntu-latest and macos-latest. However, the failure is not caused by this PR's changes.
The actual error is in test/hompair.carp:10:
The binding: Hompair.init is private; it may only be used within the module that defines it.
This is a pre-existing bug — test/hompair.carp uses the private Hompair.init constructor directly, while the working test (test/hompair-impl.carp) correctly uses the public Hompair.of. On master, this was silently swallowed because test-all.sh had no error propagation. This PR's set -euo pipefail fix correctly catches it.
The transpose tests pass (confirmed on macOS CI: all 3 assertions in hompair-impl.carp pass, including the transpose test).
Findings
Transpose fix is correct. The inner closure (fn [x] ((lookup x) i)) captured i by move, but smap calls this closure for each element — consuming i on the first call and leaving nothing for subsequent ones. Changing to @&i (copy the borrow) creates a fresh copy per call, which is the standard Carp pattern for closures that need a captured value multiple times.
test-all.sh fix is correct and valuable. Adding set -euo pipefail + quoting $f catches failures that were previously silent. This is exactly the kind of fix that prevents false-green CI.
Pre-existing issue needs attention. test/hompair.carp:10 should use (Hompair.of 1 2) instead of (Hompair.init 1 2), matching the pattern used in test/hompair-impl.carp. This is a one-line fix but it blocks CI.
No changelog to update (none exists in this repo).
Verdict: revise
Both changes are correct, but CI cannot pass until test/hompair.carp:10 is fixed. Either fix it in this PR (since the test-all.sh change is what exposes it) or open a separate PR. I'd recommend including it here since it's a single-line change and directly related to the test script fix.
Summary
Dimensional.transpose: the inner lambda capturediby move, but Carp requires captured values to be borrowed (&) or copied (@&). SincelookuptakesIndexby value, use@&ito copy on each call.test-all.shto propagatecarp -xexit codes viaset -euo pipefailand quote the file path, so test failures are no longer silently swallowed.Closes #11
Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.