modular / modular/modular

[Feature Request] Add support for recursive `@parameter` closures

Open
#3,432 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug mojo mojo-repo
Dominant language
Mojo
Stars
29.8k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Bug description

As title.

Steps to reproduce
fn fib(n: Int) -> Int:
  @parameter
  fn fib_tail(n: Int, a: Int, b: Int) -> Int:
    if n < 1:
      return 0
    elif n == 1:
      return b
    return fib_tail(n - 1, b, a + b)
  return fib_tail(n, 0, 1)
System information
Mojo 2024.8.2916 (1e9c68e6) on Docker, Intel Mac

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the recursive @parameter closure example in the reported Mojo 2024.8.2916 Docker environment and trace how the compiler handles fib_tail. Review the relevant compiler support for parameter closures; done means the example compiles and produces the expected Fibonacci result.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.