-
Notifications
You must be signed in to change notification settings - Fork 11
/
MalListVector.HC
53 lines (44 loc) · 972 Bytes
/
MalListVector.HC
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
// A unified interface for lists and vectors.
#ifndef MAL_LIST_VECTOR_HC
#define MAL_LIST_VECTOR_HC
#include "MalList.HC"
#include "MalVector.HC"
BOOL MalIsListOrVector(Malval *m)
{
return MalIsList(m) || MalIsVector(m);
}
Malval *MalHead(Malval *m)
{
NullCheck(m, "malval");
if (MalIsList(m)) return MalListHead(m);
else return MalVectorHead(m);
}
Malval *MalTail(Malval *m)
{
NullCheck(m, "malval");
if (MalIsList(m)) return MalListTail(m);
else return MalVectorTail(m);
}
Malval *MalNth(Malval *m, INT n)
{
NullCheck(m, "malval");
if (MalIsList(m)) return MalListNth(m, n);
else return MalVectorNth(m, n);
}
INT MalSize(Malval *m)
{
NullCheck(m, "malval");
if (MalIsList(m)) return MalListSize(m);
else if (MalIsVector(m)) return MalVectorSize(m);
else return 0;
}
Malval *MalCons(Malval *x, Malval *l)
{
if (MalIsVector(l)) {
return MalListCons(x, MalListOfVector(l));
}
else {
return MalListCons(x, l);
}
}
#endif