From c15edae4532f53e7e5bac9dae125c360d93f848d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 21 Feb 2015 17:27:52 +0100 Subject: 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 --- example/turing/src/tape.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 example/turing/src/tape.h (limited to 'example/turing/src/tape.h') 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, Position>, + void, + tav::Nth +>; + +// (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, Position>, + tav::Append>, + tav::ReplaceNth +>; + +} + +} + +#endif // TYPEASVALUE_EXAMPLE_TURING_SRC_TAPE_H_ -- cgit v1.2.3