anil nelakanti wrote:
I coded a small program for printing a line of the Pascal triangle
given the line number and am unable to get it compiled.

There are three problems in your code:
1. The error you get from the compiler
   is caused by an extra "end" keyword
   in the definition of "addlist".
   The innermost "end" ends the "case L2",
   the "else nil end" ends the "case L2",
   and the next one shouldn't be there.
2. Function names should always be Uppercase.
     fun {Inc X} X+1 end
   has about the same effect as
     Inc = fun {$ X} X+1 end
   i.e. the variable Inc is bound to function.
3. The nesting of parenthesis in the function
   pascal is buggy.

More style recommendations:
i) Most people do not put a whitespace
   after { or before }, I think.
ii) Personally, I prefer to make the
    bracketing explicit whenever I
    write an expression left to the
    | operator, like
      (H1+H2) | {AddList T1 T2}

If you compile the attached file with
  ozc -x pascal.oz
it seems to work.

HTH,
Andreas
functor
import
   Application
   Browser
   
define
   
   fun {ShiftLeft L3}
      case L3 of H|T then
         H|{ShiftLeft T}
      else [0] end
   end
   
   fun {ShiftRight L}
      0|L
   end
   
   fun {AddList L1 L2}
      case L1 of H1|T1 then
         case L2 of H2|T2
         then
            (H1+H2)|{AddList T1 T2}
         end
      else nil end
   end

   fun {Pascal N}
      if N==1 then [1]
      else
         {AddList
          {ShiftLeft {Pascal N-1}}
          {ShiftRight {Pascal N-1}}}
      end
   end

   {Browser.browse {Pascal 5 } }
   
end
_________________________________________________________________________________
mozart-users mailing list                               
mozart-users@ps.uni-sb.de
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to