ohua-dev / ohuac

A standalone compiler for ohua algorithms
Eclipse Public License 1.0
1 stars 0 forks source link

Algorithm sorting needs to be aware of recursion #17

Closed JustusAdam closed 5 years ago

JustusAdam commented 5 years ago

With recursion a top level algo might reference itself which, due to the naivety of the function sorting the algos before compilation, leads to a Unsortable! (Probably due to a cycle) error. The function in question should be appropriately changed to account for recursive functions.

Workaround

The same issue does not apply to locally defined functions. By making the recursive function local, recursion can be used.

aka a source file with

fn go (n:i32) {
   if (lt(n, 0)) { n } else { go(minus(n,3)) }
}

can be written as

fn go (n:i32) {
   let go0 = | n0 | (if (lt(n0, 0)) { n0 } else { go0(minus(n0,3)) });
   go0(n)
}

and will then be accepted by the compiler

JustusAdam commented 5 years ago

Has been fixed