Make a decreasing list from a number

92 views Asked by At

I need to create a decreasing list of all whole numbers between X and Y (inclusive).

I am trying this:

declare
local
   fun {Dec From To}
      From | {Dec From-1 To}
   end
in
   {Browse {Loop 8 1}} % Should Display: [8, 7, 6, 5, 4, 3, 2, 1]
end

The Mozart compiler shows that the code is accepted, but no Browse window opens up.

What is wrong?

1

There are 1 answers

0
Alma A On BEST ANSWER

I think nothing is shown because your function Dec is an infinite loop because you never set when to stop, and that's why the browse window is not displayed.

The function should be:

fun {Dec From To}
  if From == To then 
    nil
  else
    From | {Dec (From-1) To}
  end
end 

I hope this was helpful :)