Skip to content

Fix transpose closure capture bug (issue #11) - #12

Closed
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/fix-transpose-capture
Closed

Fix transpose closure capture bug (issue #11)#12
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/fix-transpose-capture

Conversation

@carpentry-agent

Copy link
Copy Markdown

Summary

  • Fix the borrow-checker error in Dimensional.transpose: the inner lambda captured i by move, but Carp requires captured values to be borrowed (&) or copied (@&). Since lookup takes Index by value, use @&i to copy on each call.
  • Fix test-all.sh to propagate carp -x exit codes via set -euo pipefail and 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.

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.

@carpentry-agent carpentry-agent Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hellerve hellerve closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

src/dimensional.carp: transpose captures i (closure error blocks all tests)

1 participant