# Recursion in Chapel

**URL:** <https://chapel.discourse.group/t/recursion-in-chapel/48664>\
**Category:** Users\
**Created:** [March 27, 2026, 12:40am UTC](https://chapel.discourse.group/t/recursion-in-chapel/48664 "2026-03-27T00:40:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![00shiv](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/00shiv/32/747_2.png) [@00shiv](https://chapel.discourse.group/u/00shiv)\
**Post date:** [March 27, 2026, 12:40am UTC](https://chapel.discourse.group/t/recursion-in-chapel/48664/1 "2026-03-27T00:40:39Z")

</div>

For the first time I am writing a recursive parallel code in Chapel and it seems to send the compiler (both 2.7 and 2.8) into an endless loop repeatedly printing out the 1 statement:

“stoneNetr.chpl:172: called as construct(ys: [domain(1,int(64),one)] int(64), zs: [domain(1,int(64),one)] int(64)) from function 'construct'“

The code is already fairly long, so before I try to cut it down to post I was wondering whether Chapel actually supported recursive codes where the child function calls are inside cobegin statements?

Thanks.

–shiv–

---

<div class="post-metadata">

**Author:** ![bradcray](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/bradcray/32/72_2.png) [@bradcray](https://chapel.discourse.group/u/bradcray)\
**Post date:** [March 27, 2026, 1:26am UTC](https://chapel.discourse.group/t/recursion-in-chapel/48664/2 "2026-03-27T01:26:50Z")

</div>

Hi @00shiv —

I'm not aware of any reason that a recursive call within a `cobegin` isn't intended to work in Chapel (and even if it were intended, the compiler still shouldn't go into an infinite loop 🙂 ).

Rather than cutting the code down to a smaller size, I wonder whether you'd be able to replicate the pattern of recursive parallelism in a new test to see if you got the same behavior?

You're welcome to share your full code if you're comfortable doing so (which is to say, while small reproducers are nice, a long code wouldn't necessarily make it harder for us to debug). Or, if you're uncomfortable sharing your full code, iI'd be curious to see key excerpts, like:

- the definition and call to the `construct()` procedure that the error above is referring to
- the approximate structure of the `cobegin` it's taking place within

The part of the error message before the endlessly repeated line you gave above would be interesting as well.

Curious to learn more,  
-Brad

---

<div class="post-metadata">

**Author:** ![00shiv](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/00shiv/32/747_2.png) [@00shiv](https://chapel.discourse.group/u/00shiv)\
**Post date:** [March 27, 2026, 2:19am UTC](https://chapel.discourse.group/t/recursion-in-chapel/48664/3 "2026-03-27T02:19:56Z")

</div>

In the process of trying to create a minimal code I ended up finding a bunch of other bugs in my code. Fixing those made the compiler happy again! The downside is that I lost the original code that caused the infinite loop in the compiler!

–shiv–

---

<div class="post-metadata">

**Author:** ![bradcray](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/bradcray/32/72_2.png) [@bradcray](https://chapel.discourse.group/u/bradcray)\
**Post date:** [March 27, 2026, 2:29pm UTC](https://chapel.discourse.group/t/recursion-in-chapel/48664/4 "2026-03-27T14:29:44Z")

</div>

OK, glad that you've got traction again, but sorry to hear that we lost  
the infinite code. Needless to say, if you come back across it again,  
we'd be interested in examining that.

-Brad
