modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
22.87k stars 2.58k forks source link

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

Open soraros opened 2 weeks ago

soraros commented 2 weeks ago

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
bpr commented 1 week ago

https://github.com/modularml/mojo/blob/17662e30fd306f3d307bd93eb1614a6dea36892c/docs/roadmap.md?plain=1#L599

soraros commented 1 week ago

@bpr Ah, right. Let me make this a feature request for @parameter closures.

Actually, I'm not so sure now. I think the roadmap was written before the new closure model, so it was taking about @parameter fib_tail not fib_tail which was in my original bug report. At least the compiler should give proper error message if @parameter's missing.