You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fn fact(n : Int) -> Int:
fn factint(p : Int, m : Int) -> Int:
if m == 0:
return p
return factint(p*m, m-1)
return factint(1, n)
and got the compilation error:
error: Expression [6]:5:1: cyclic reference between expressions defining and using parameters
fn fact(n : Int) -> Int:
^
Expression [6]:6:5: parameter "factint($Int::Int,$Int::Int)" is defined here, which references itself
fn factint(p : Int, m : Int) -> Int:
^
A simpler recursive fact without the tail-recursive helper does compile, and a top-level factint compiles, so the problem seems to be related to factint being internal to fact.
I believe it is related to this defined in the Mojo docs:
Nested functions (any function that is not a top-level function) cannot be recursive in any way. Nested functions are considered “parameters”, and although parameter values do not have to obey lexical order, their uses and definitions cannot form a cycle. Current limitations in Mojo mean that nested functions, which are considered parameter values, cannot be cyclic.
Bug Description
I defined:
and got the compilation error:
A simpler recursive
fact
without the tail-recursive helper does compile, and a top-levelfactint
compiles, so the problem seems to be related tofactint
being internal tofact
.Context
The text was updated successfully, but these errors were encountered: