declare fun {Hailstone N} if {IsOdd N} then (3*N+1) div 2 else N div 2 end end % Return a list of the iterates of N. fun {IterHailstone N} fun {IterHelper N Lst#EndVar} if N == 1 then EndVar = N|nil Lst else local Next = {Hailstone N} in local Z in EndVar = N|Z {IterHelper Next Lst#Z} end end end end in local End in {IterHelper N End#End} end end