#ifndef TYPEASVALUE_EXAMPLE_TURING_MACHINE_H_ #define TYPEASVALUE_EXAMPLE_TURING_MACHINE_H_ #include "conditional/cond.h" #include "state.h" #include "tape.h" namespace machine { // (define (simulate transition tape state position) // (if (= state FINAL) // tape // (let* ((current_symbol (readSymbol position tape)) // (current_state (transition state current_symbol)) // (direction (nth MOVE current_state)) // (next_symbol (nth WRITE current_state)) // (next_state (nth NEXT current_state)) // (next_position (cond ((= direction RIGHT) (+ position 1)) // ((= direction LEFT) (- Position 1)) // (else position)))) // (simulate transition // (writeSymbol position next_symbol tape) // next_state, // next_position))) template < template class Transition, typename State, typename Tape, typename Position > class simulate { private: using current_symbol = tape::readSymbol; using current_state = Transition; using direction = tav::Nth; using next_symbol = tav::Nth; using next_state = tav::Nth; using next_position = tav::Cond< tav::Branch< tav::IsEqualValue>, tav::Add> >, tav::Branch< tav::IsEqualValue>, tav::Substract> >, tav::Else< Position > >; static_assert( tav::Not>>::value, "next position out of bounds" ); public: using type = tav::Eval, next_position >>; }; template < template class Transition, typename Tape, typename Position > struct simulate { typedef Tape type; }; // (define (run program state tape position) // (simulate (transition program) // tape // state // position)) template < typename Program, typename State, typename Tape, typename Position > using run = tav::Eval::template state, State, Tape, Position >>; } #endif // TYPEASVALUE_EXAMPLE_TURING_MACHINE_H_