diff options
author | Adrian Kummerlaender | 2015-02-21 17:27:52 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-02-21 17:27:52 +0100 |
commit | c15edae4532f53e7e5bac9dae125c360d93f848d (patch) | |
tree | 58a3ded412834ba730aea9ebe6874e4ee4920975 /example/turing/src/tape.h | |
parent | effddfdd69cf9e5ec700aeda2980c0210575e320 (diff) | |
download | TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.gz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.bz2 TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.lz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.xz TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.tar.zst TypeAsValue-c15edae4532f53e7e5bac9dae125c360d93f848d.zip |
Separated Turing machine implementation into components
* i.e. separate namespaces and headers for _Tape_ and _State_ functions
* `void` is now used as the `BLANK` field value
Diffstat (limited to 'example/turing/src/tape.h')
-rw-r--r-- | example/turing/src/tape.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/example/turing/src/tape.h b/example/turing/src/tape.h new file mode 100644 index 0000000..39814d8 --- /dev/null +++ b/example/turing/src/tape.h @@ -0,0 +1,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_ |