-
Notifications
You must be signed in to change notification settings - Fork 0
/
mal_types.py
77 lines (57 loc) · 1.84 KB
/
mal_types.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import re
class atom(object):
def __init__(self, x):
self.reference = x
class Symbol:
def __init__(self, name):
self.name = name
def __eq__(self, other):
if isinstance(other, Symbol) and self.name == other.name:
return True
else:
return False
class Function:
def __init__(self, x, params, env, fn, is_macro = False):
self.x = x
self.params = params
self.env = env
self.fn = fn
self.is_macro = is_macro
self.metadata = None
class bool:
def __init__(self):
pass
class true(bool):
def __init__(self):
super().__init__()
self.value = True
class false(bool):
def __init__(self):
super().__init__()
self.value = False
class Array(list):
def __init__(self, x, bracket):
super().__init__(x)
self.metadata = None
if bracket == "(":
self.type = "list"
elif bracket == "[":
self.type = "vector"
elif bracket == "{":
self.type = "hash-map"
else:
raise ValueError("Invalid array type")
def __eq__(self, other):
if isinstance(other, Array) and self.type in ["list","vector"] and self.type == other.type and super().__eq__(other):
return True
elif isinstance(other, Array) and self.type == "hash-map" and self.type == other.type:
ans = True
for i in range(0, len(self), 2):
if (self[i] not in other) or (self[i+1] != other[other.index(self[i])+1]):
ans = False
break
if len(self) != len(other):
ans = False
return ans
else:
return False