Loading ...
Sorry, an error occurred while loading the content.

333tail recursion

Expand Messages
  • renzolon
    Jun 1, 2002
      Hello!
      I'm writimg a function to build a list from a file with more than
      27000 lines.
      I've tried with something like:


      let rec pmatch inp path =
      try
      let s= try
      Str.string_after (input_line(inp)) 17
      with End_of_file -> raise End
      in

      if Str.string_match (Str.regexp path) s 0
      then begin [s] @ (pmatch inp path) end
      else
      (pmatch inp path)
      with
      End ->[]
      ;;


      It compiles perfectly, but when i ran it.. it gives me "stack
      overflow"..

      I know that ocamlc optimizes tail recursive calls, but i didn't
      understand very well its mechanism..

      Does anyone know how can i rewrite the function in a tail-recursive
      way?


      Thank you,
      Lorenzo Natile
    • Show all 44 messages in this topic