From a3a75aefa3597c393756e9f9405398a450d2c9f6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 21 Feb 2015 18:19:58 +0100 Subject: Moved Turing machine printing into separate function --- example/turing/src/machine.h | 6 ++-- example/turing/turing.cc | 83 +++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/example/turing/src/machine.h b/example/turing/src/machine.h index 2404d9a..c1338e1 100644 --- a/example/turing/src/machine.h +++ b/example/turing/src/machine.h @@ -1,5 +1,5 @@ -#ifndef TYPEASVALUE_EXAMPLE_TURING_MACHINE_H_ -#define TYPEASVALUE_EXAMPLE_TURING_MACHINE_H_ +#ifndef TYPEASVALUE_EXAMPLE_TURING_SRC_MACHINE_H_ +#define TYPEASVALUE_EXAMPLE_TURING_SRC_MACHINE_H_ #include "conditional/cond.h" @@ -95,4 +95,4 @@ using run = tav::Eval, tav::Int<0>, tav::Int<1>, tav::Size<1>, tav::Char<'R'>> >; -// (define mirror_initial_tape (list 1 1 1 0 0 0 0)) -using mirror_initial_tape = tav::ListOfType; - -// (define mirror_final_tape -// (run mirror -// 1 -// mirror_initial_tape -// 0)) -using mirror_final_tape = machine::run< - mirror, - tav::Size<1>, - mirror_initial_tape, - tav::Size<0> ->; - // (define busy_beaver (list (list 'A' 0 1 'B' 'R') [...])) using busy_beaver = tav::List< // [state] [read] [write] [next state] [head movement] @@ -46,49 +31,53 @@ using busy_beaver = tav::List< tav::List, tav::Int<1>, tav::Int<1>, void, tav::Char<'N'> > >; -// (define busy_beaver_initial_tape (make-list 13 0)) -using busy_beaver_initial_tape = tav::MakeList, tav::Int<0>>; - -// (define busy_beaver_final_tape -// (run busy_beaver -// 'A' -// busy_beaver_initial_tape -// 6)) -using busy_beaver_final_tape = machine::run< - busy_beaver, - tav::Char<'A'>, - busy_beaver_initial_tape, - tav::Size<6> ->; - -int main(int, char **) { +template < + typename Initial, + typename Final +> +void printStates(const std::string& name) { const auto printField = [](const int x) { std::cout << x << " "; }; - std::cout << "1. Mirror" - << std::endl - << " Initial: "; - - tav::runtime::for_each(printField); - - std::cout << std::endl - << " Final: "; - - tav::runtime::for_each(printField); - - std::cout << std::endl - << std::endl - << "2. Busy Beaver" + std::cout << name << std::endl << " Initial: "; - tav::runtime::for_each(printField); + tav::runtime::for_each(printField); std::cout << std::endl << " Final: "; - tav::runtime::for_each(printField); + tav::runtime::for_each(printField); std::cout << std::endl; } + +int main(int, char **) { + // (define mirror_tape (list 1 1 1 0 0 0 0)) + using mirror_tape = tav::ListOfType; + + printStates< + mirror_tape, + machine::run< + mirror, + tav::Size<1>, + mirror_tape, + tav::Size<0> + > + >("1. Mirror"); + + // (define busy_beaver_tape (make-list 13 0)) + using busy_beaver_tape = tav::MakeList, tav::Int<0>>; + + printStates< + busy_beaver_tape, + machine::run< + busy_beaver, + tav::Char<'A'>, + busy_beaver_tape, + tav::Size<6> + > + >("2. Busy Beaver"); +} -- cgit v1.2.3