various updates

This commit is contained in:
Kyle Isom 2018-04-10 07:09:04 -07:00
parent 1654f1b14f
commit b7193a9e96
2 changed files with 28 additions and 12 deletions

View File

@ -7,6 +7,7 @@ topics.
Projects Projects
-------- --------
+ ``adsep/``: `Algorithms + Data Structures = Programs <https://en.wikipedia.org/wiki/Algorithms_%2B_Data_Structures_%3D_Programs>`_
+ ``blue-pill/``: blue pill experiments + ``blue-pill/``: blue pill experiments
+ ``lpn/``: `Learn Prolog Now <http://lpn.swi-prolog.org/>`_ + ``lpn/``: `Learn Prolog Now <http://lpn.swi-prolog.org/>`_
+ ``misc/``: A scratchpad of random programs; a replacement for + ``misc/``: A scratchpad of random programs; a replacement for

View File

@ -1,18 +1,33 @@
#lang racket #lang racket
;;; a turing machine implementation (define instruction
(define tape (make-hash)) '(("B" "s1") . ("X" "R" "s2")))
(define (lookup position) ;;; The tape utility functions should hide the actual tape
;;; representation.
(define (tape-lookup tape position)
(unless (hash-has-key? tape position) (unless (hash-has-key? tape position)
(hash-set! tape position 0)) (hash-set! tape position "B"))
(hash-ref tape position)) (hash-ref tape position))
(define turing-machine% (define (tape-write tape position sym)
(class object% (hash-set! tape position sym))
(init)
(define tape (make-hash)) (define (head-update head head_dir)
(define head 0) (cond
(define current-state #f) [(equal? head_dir "R") (+ head 1)]
(define state-table) [(equal? head_dir "L") (- head 1)]
(super-new))) [else (error "invalid head direction")]))
(define (turing-update tape head state instruction)
(tape-write tape head (car instruction))
(values tape
(head-update head (car (cdr instruction)))
(car (cdr (cdr instruction)))))
(define (turing-instruction tape instructions)
(for (instruction instructions)
;; does the car match the tape and the head position?
;; if it does, break the loop and return the instruction
;; keep going
))