Hooks and recursion depth
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
The recursion depth seems to jump by a pretty large chunk when using hooks:
```m2
i1 : fact1 = method();
i2 : addHook((fact1, ZZ), n -> 1);
i3 : addHook((fact1, ZZ), n -> if n > 0 then n * fact1(n - 1));
i4 : fact1 ZZ := n -> (print recursionDepth(); runHooks((fact1, ZZ), n));
i5 : fact1 10
2
14
26
38
50
62
74
86
98
110
122
o5 = 3628800
```
Compare to:
```m2
i6 : fact2 = method();
i7 : fact2 ZZ := n -> (print recursionDepth(); if n > 0 then n * fact2(n - 1) else 1);
i8 : fact2 10
2
3
4
5
6
7
8
9
10
11
12
o8 = 3628800
```
Why is this? It makes it pretty easy to hit the recursion limit when using hooks.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the two factorial examples using addHook, runHooks, and recursionDepth, then trace how hook dispatch changes the call depth. Compare the hook-based trace with the direct fact2 trace; done means the cause of the larger increments is identified and the expected behavior or limitation is documented.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100