This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Josh Ackerman
Posted Jun 12 - Read on Facebook

Hello,

I programmed a quick and simple fractal example in FramerJS, but the program seems to go into an infinite recursive loop.

Since this should be such a simple program to write, as a sanity check, I successfully programmed this in python. So I am guessing that I am either missing some really easy bug in my CoffeeScript implementation that I subconsciously fixed in my python implementation, or there some strange CoffeeScript behavior that I don't know about.

Here is the example. To see the bug you will need to uncomment the recursive calls in the drawHFractal function.

Any help would be appreciated.

3 Comments

Koen Bok

Very cool project! I'd love some high level fractal explanation for designers if you'd be up for that :-)

It looks like you missed a return in your level check condition. If I add it and start at level 3 it works: http://share.framerjs.com/t9o0c26oglw0/

Josh Ackerman

Thanks for the help. However I was under the impression that functions do not necessarily need an explicit return statement in CoffeeScript? For instance why does the function below return the desired value but I need a return statement in this case?

fn = (n) ->
factorial = if n == 1 then 1 else n*fn(n-1)
factorial

Also from the CoffeeScript docs "You might have noticed how even though we don't add return statements to CoffeeScript functions, they nonetheless return their final value."

Koen Bok

Yeah this can be confusing. The implicit return only works at the _end_ of a function body. If you want to return early you need to make it explicit.

http://coffeescript.org/#try:a%20%3D%20-%3E%0A%0A%20%20b%20%3D%205%0A%0A%20%20if%201%20%3D%3D%200%0A%20%20%20%20return%20b%0A%20%20%0A%20%20b

Read the entire post on Facebook