jonathanhogg / flitter

A functional programming language and declarative system for describing 2D and 3D visuals
https://flitter.readthedocs.io
BSD 2-Clause "Simplified" License
34 stars 1 forks source link

Forcing use of unsupported recursion causes kind of horrible errors expected of using recursion #24

Closed jonathanhogg closed 6 months ago

jonathanhogg commented 6 months ago

Flitter does not support recursion.

That said, you can of course make it recurse with this one hack:

func fib(fib, n)
  if n > 1
    fib(fib, n-1) + fib(fib, n-2)
  else
    n

debug(fib(fib, 10))

Sadly this will cause the simplifier to explode because it attempts to statically evaluate this recursion. The implementation of tree.IfElse.simplify() eagerly evaluates the then expression of the if and chokes on its own stack.

jonathanhogg commented 6 months ago

Swapping the if around so that the recursive call comes in the else expression fixes the problem, but perhaps this is a sign that the simplifier should be smarter about not trying to evaluate expressions it doesn't need to.