-2
local MainSum in
  fun {MainSum N}
    local Sum in 
      fun {Sum N Acc} 
        if N==0 then Acc 
          else Acc+{Sum N-1 N*N} 
        end 
      end 
     {Sum 5 0}
     end
  end
end

When i Try this codes it shows following error

%************************** syntax error ************************
%**
%** nesting marker expected as designator of nested function
%**
%** in file "exercise.oz", line  2, column 7
%** ------------------ rejected (1 error)
Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
  • 2
    You really could've and should've given us more to work with; just saying "unable to run this code" 1. isn't a question and 2. gives us no clue about what's actually happening. We don't know if there's an error, if your code is crashing, if you're accidentally creating a black hole that's swallowing a dozen small asteroids on every run. If you want us to be able to help, give us information. The more information the better. – cf- Mar 30 '14 at 19:10
  • Just provide more info, please – Artem Bilan Mar 30 '14 at 19:18
  • I am really sorry for my mistake – user3478837 Mar 31 '14 at 13:47

1 Answers1

1

You code work on my computer... But you didn't use the argument of MainSum

I believe that's what you wanted to do:

local MainSum in
   fun {MainSum N}
      local Sum in 
         fun {Sum N Acc} 
            if N==0 then Acc 
            else Acc+{Sum N-1 N*N} 
            end 
         end 
         {Sum N 0}
      end
   end

   {Browse {MainSum 5}}
end

which can be written, using a more concise notation, and using terminal recursion!

local
   fun{MainSum N}
      fun{Sum N Acc}
         if N==0 then Acc
         else {Sum N-1 N*N+Acc}
         end
      end
   in
      {Sum N 0}
   end
in
   {Browse {MainSum 5}}
end
yakoudbz
  • 903
  • 1
  • 6
  • 14