blob: 39814d860cccfe6f24c374af8dc79262d0d046be (
plain)
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
|
#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"
namespace machine {
namespace tape {
// (define (readSymbol position tape)
// (if (= (length tape) position)
// '()
// (nth position tape)))
template <
typename Position,
typename Tape
>
using readSymbol = tav::If<
tav::IsEqualValue<tav::Length<Tape>, Position>,
void,
tav::Nth<Position, Tape>
>;
// (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_
|