-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist.hh
More file actions
40 lines (32 loc) · 905 Bytes
/
Copy pathlist.hh
File metadata and controls
40 lines (32 loc) · 905 Bytes
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
#ifndef _XT_LIST_H_
#define _XT_LIST_H_
#include "object.hh"
#include "exceptions.hh"
#include "seq.hh"
namespace xt {
struct _List;
struct _List {
_List(Object first, std::shared_ptr<_List> rest, int count) : first(first), count(count), rest(rest) { }
const Object first;
const int count;
const std::shared_ptr<_List> rest;
static TypeInfo type_info;
};
typedef std::shared_ptr<_List> List;
class LSeq : public ISeq {
public:
const List l;
LSeq(const List l): l(l) {}
virtual Object first() const;
virtual Seq next() const;
};
namespace list {
List cons(Object o);
List cons(List list, Object o);
inline bool is_list(Object o) { return o.typeinfo == &_List::type_info; }
inline Seq to_seq(List l) { return Seq(new LSeq(l)); }
inline List to_list(Object o) { if (!is_list(o)) throw RuntimeException("Not a List"); return std::static_pointer_cast<_List>(o.ptr); }
List empty();
}
}
#endif