Download GODI User`s Manual
Transcript
Chapter 2 Using GODI In this chapter, I would like to give some hints for O’Caml beginners, and explain where to find what in the GODI environment. 2.1 Starting the OCaml toploop The O’Caml bytecode compiler can be called as a so-called toploop: The user can enter declarations and expressions, and these are immediately compiled to bytecode, and immediately executed. The toploop is very handy for coding attempts, and also an interesting debugging aid for larger programs (because one can load already compiled bytecode into the toploop, too). One can invoke the toploop with the command ocaml: $ ocaml Objective Caml version 3.08.1 # For example, define the faculty function as (note that the # at the beginngin of the line is the prompt symbol, and that the ;; at the end of the line indicates the end of the user input): # let rec fac n = if n <= 1 then 1 else n * fac(n-1);; The toploop answers with: val fac : int -> int = <fun> This means that fac is a function taking integers as input, and returning integers as results. Call the function as # fac 10;; 14