-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.ml
42 lines (37 loc) · 1.35 KB
/
debug.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
open Types
let string_of_pair (x, y) =
"(" ^ (string_of_float x) ^ ", " ^ (string_of_float y) ^ ")"
let string_of_thing = function
| Number n -> "Number: " ^ (string_of_float n)
| String s -> "String: " ^ s
| Point p -> "Point: " ^ (string_of_pair p)
| Figure f ->
begin
match f with
| L (l1, l2) -> "Line: from " ^
(string_of_pair l1) ^
" to " ^
(string_of_pair l2)
| P parr -> Array.fold_left (fun s p -> s ^ " " ^ (string_of_pair p))
"Polygon:" parr
| C (c, r) -> "Circle: center " ^
(string_of_pair c) ^
" radius " ^
(string_of_float r)
| E (f1, f2, len) -> "Ellipse: focal1 " ^
(string_of_pair f1) ^
" focal2 " ^
(string_of_pair f2) ^
" length " ^
(string_of_float len)
end
let print_thing th =
print_endline (string_of_thing th)
let print_stack st =
print_endline "STACK: " ;
Stack.iter print_thing st
let print_dictionary dict =
print_endline "VARIABLES: " ;
Hashtbl.iter (fun name value ->
print_string (name ^ " --> ") ;
print_thing value) dict