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
|
#ifndef TYPEASVALUE_EXAMPLE_TURING_SRC_TAPE_H_
#define TYPEASVALUE_EXAMPLE_TURING_SRC_TAPE_H_
#include "type.h"
#include "list/list.h"
#include "list/operation/replace_nth.h"
#include "conditional/if.h"
#include "function/apply.h"
namespace machine {
namespace tape {
struct BLANK {
typedef BLANK type;
static constexpr char value{'\0'};
};
// (define (readSymbol position tape)
// (if (= (length tape) position)
// '()
// (nth position tape)))
template <
typename Position,
typename Tape
>
using readSymbol = tav::Eval<tav::If<
tav::LowerThan<Position, tav::Length<Tape>>,
tav::Apply<tav::Nth, Position, Tape>,
BLANK
>>;
// (define (writeSymbol position symbol tape)
// (if (= (length tape) position)
// (append tape (list symbol))
// (replace-nth position symbol tape)))
template <
typename Position,
typename Symbol,
typename Tape
>
using writeSymbol = tav::If<
tav::IsEqualValue<tav::Length<Tape>, Position>,
tav::Append<Tape, tav::List<Symbol>>,
tav::ReplaceNth<Position, Symbol, Tape>
>;
}
}
#endif // TYPEASVALUE_EXAMPLE_TURING_SRC_TAPE_H_
|