1(**************************************************************************) 2(* *) 3(* OCaml *) 4(* *) 5(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6(* *) 7(* Copyright 1995 Institut National de Recherche en Informatique et *) 8(* en Automatique. *) 9(* *) 10(* All rights reserved. This file is distributed under the terms of *) 11(* the GNU Lesser General Public License version 2.1, with the *) 12(* special exception on linking described in the file LICENSE. *) 13(* *) 14(**************************************************************************) 15 16let rec tak (x, y, z) = 17 if x > y then tak(tak (x-1, y, z), tak (y-1, z, x), tak (z-1, x, y)) 18 else z 19 20let break_handler _ = 21 print_string "Thank you for pressing ctrl-C."; print_newline(); 22 print_string "Allocating a bit..."; flush stdout; 23 ignore (tak(18,12,6)); print_string "done."; print_newline() 24 25let stop_handler _ = 26 print_string "Thank you for pressing ctrl-Z."; print_newline(); 27 print_string "Now raising an exception..."; print_newline(); 28 raise Exit 29 30let _ = 31 ignore (Sys.signal Sys.sigint (Sys.Signal_handle break_handler)); 32 ignore (Sys.signal Sys.sigtstp (Sys.Signal_handle stop_handler)); 33 begin try 34 print_string "Computing like crazy..."; print_newline(); 35 for i = 1 to 1000 do ignore (tak(18,12,6)) done; 36 print_string "Reading on input..."; print_newline(); 37 for i = 1 to 5 do 38 try 39 let s = read_line () in 40 print_string ">> "; print_string s; print_newline() 41 with Exit -> 42 print_string "Got Exit, continuing."; print_newline() 43 done 44 with Exit -> 45 print_string "Got Exit, exiting."; print_newline() 46 end; 47 exit 0 48