"on" should trace the individual methods of a method function
Nobody has claimed this yet.
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
This issue was triaged from [`bugs/dan/0-on`](https://github.com/Macaulay2/M2/blob/388c1ff0ce30d83751dea7bc7eac77fdc1305dd7/bugs/dan/0-on), one of the 857 files removed from the pre-GitHub `bugs/` tree by [`d2c8d27826`](https://github.com/Macaulay2/M2/commit/d2c8d27826) and catalogued in [#36](https://github.com/Macaulay2/M2/issues/36). **The commentary below was written by Claude (Claude Opus 5, via Claude Code)**, not by @d-torrance, whose account posted it -- please weigh it accordingly.
### The original file, verbatim
```text
"on" should do something for all methods of a method function,
like this:
on2 = f -> scan(methods f, m -> (
installMethod append ( m , on( lookup m, Name => "method for " | toString m#0 | " " | toString unsequence drop(m,1)));
))
It should treat method functions with options properly, digging
in one level deeper.
This almost works:
--- debugging.m2 (revision 14504)
+++ debugging.m2 (working copy)
@@ -47,6 +47,18 @@
if not callCount#?fb then callCount#fb = 0;
limit := opts.CallLimit;
if not instance(f, Function) then error("expected a function");
+ if instance(f, MethodFunction) then (
+ scan(methods f, m -> (
+ on( lookup m, Name => "method for " | toString m );
+ ));
+ return;
+ );
+ if instance(f, MethodFunctionWithOptions) then (
+ scan(methods f, m -> (
+ on( (lookup m) {}, Name => "method for " | toString m);
+ ));
+ return;
+ );
fn := if opts.Name =!= null then opts.Name else try toString f else "{*function*}";
x -> (
saveCallCount := callCount#fb = callCount#fb+1;
but not all method function (such as toString, toExternalString) are in one of those classes.
```
### Where it stands today
Still unmet, and the obvious workaround does not reach the interesting case.
### Why `f = on f` is not enough
It works only for functions you defined yourself. For Core method functions — the ones actually worth
tracing — the rebinding is refused:
```m2
i1 : basis = on basis
error: ... protected global
```
Dan's route in the file does work, and traces real calls including ones made from library code:
```m2
installMethod(basis, ZZ, Module, on(lookup m, Name => ...))
```
### Three gaps stand
1. **`on` labels by argument, not by method.** `foo(2,3)` prints `Sequence`, and an inherited call
prints the argument's class rather than the method that actually ran — so a trace of a method
function does not tell you which method it went to.
2. **There is no way to trace in place** without rebinding the name, which is what the protected-global
error blocks.
3. **For a `MethodFunctionWithOptions` the trace shows the wrapper**, an `OptionTable` and a
`FunctionClosure`, instead of the real arguments. That is the *"digging in one level deeper"* the
file asks for.
### A gap in the file's own draft, now wider
The patch in the file classifies functions into two cases and misses `toString` and `toExternalString`,
which are in neither — and the classification has grown a third case since, because
`MethodFunctionSingle` now exists as well.
`open` · disposition `issue` · source of truth: [`bug-triage/catalog.tsv`](https://github.com/d-torrance/M2/blob/bug-triage/bug-triage/catalog.tsv)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with debugging.m2 and the existing `on` entry point, then inspect how `methods`, `lookup`, `installMethod`, and the MethodFunction variants are handled. Done means tracing identifies the individual method that runs, supports in-place tracing of protected globals, and exposes real arguments for MethodFunctionWithOptions, including the newer MethodFunctionSingle case.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100