These are chat archives for mozart/mozart2

2nd
Jan 2018
TotOrO
@nikhilka08
Jan 02 2018 08:59
I'm trying to do exercise from the book "Concepts,techniques and model of computer programming" and for Chapter 1 Ex. 2 here is my code which gives me error "nesting marker expected as designator of nested function"
Here is my code
declare Fac S
 fun {Fac N}
       if N==0 then 1 else N*{Fac N-1} end
    end
% {Browse {Fac 5} }

declare fun {Mul N R} % For n*(n-1)*...*(n-r+1) 
       local S = N-R+1 in
          fun {Mul2 N S}
         if N==S then N else  N*{Mul2 N-1 S} end         
          end
       end
    end


declare fun {Comb N R}
  if R==0 then 1 else  {Mul N R} div {Fac R} end
end
If someone can please help, i read about nesting marker but was not able to figure out how to use them
Chris Double
@doublec
Jan 02 2018 12:17
I don't understand the definition of Mul
It seems to be returning a function called Mul2
Did you expect something like:
declare
fun {Mul N R} % For n*(n-1)*...*(n-r+1) 
   local
      S = N-R+1
      fun {Mul2 N S}
         if N==S then N else  N*{Mul2 N-1 S} end         
      end
   in
      ..call Mul2 here..
   end
end
That's why you're getting the error btw, the nested function is messed up.