]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Collaz.scl
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Collaz.scl
1 import "Prelude"
2
3 f x = if x `mod` 2 == 0
4       then x `div` 2
5       else 3*x + 1
6 fd x = unfoldr (\x -> do
7                    r = f x 
8                    if x == 1
9                    then Nothing
10                    else Just (x,r)
11                 ) x
12
13 //main :: [Integer]                
14 main = fd 7
15 --
16 [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2]