Browse Source

ok i messed up the last commit, fix it

master
John Whitley 3 weeks ago
parent
commit
9340ac9b05
3 changed files with 1 additions and 60 deletions
  1. 1
    1
      .gitignore
  2. 0
    7
      markov.asd~
  3. 0
    52
      markov.lisp~

+ 1
- 1
.gitignore View File

@@ -16,4 +16,4 @@
*.sx32fsl
*.wx64fsl
*.wx32fsl
*\~

+ 0
- 7
markov.asd~ View File

@@ -1,7 +0,0 @@
(defsystem "markov"
:description "Markov is a simple library for Markov Chains."
:version "0.0.1"
:depends-on ("alexandria" "cl-utilities")
:components ((:file "packages")
(:file "macros" :depends-on ("packages"))
(:file "hello" :depends-on ("macros"))))

+ 0
- 52
markov.lisp~ View File

@@ -1,52 +0,0 @@
(require 'cl-utilities)
(require 'alexandria)
(defun read-file-into-list (filename)
(with-open-file (stream filename)
(loop for line = (read-line stream nil)
while line
collect line)))
(defun concat-spaces (strs)
(remove #\Space (apply #'concatenate 'string
(mapcar #'(lambda (x) (concatenate 'string x " ")) strs))
:count 1 :from-end t))
(defun copy-table (table)
(let ((new-table (make-hash-table
:test (hash-table-test table)
:size (hash-table-size table))))
(maphash #'(lambda(key value)
(setf (gethash key new-table) value))
table)
new-table))
(defun pick-node (node)
(if (second node)
(nth (random (length (second node))) (second node))
nil))
(defun build-chain (inode terminator termstr &optional inlist)
(let ((startnode (if (symbolp inode) (eval inode) inode)))
(cond
((equal termstr (first startnode)) inlist)
((not (second startnode)) (append inlist (list (first startnode))))
((zerop (1- terminator)) (append inlist (list (first startnode))))
(t (build-chain (pick-node startnode)
(1- terminator)
termstr
(append inlist (list (first startnode))))))))
(defun build-random-chain (table terminator termstr)
(build-chain
(gethash (nth (random (length
(alexandria:hash-table-keys table)))
(alexandria:hash-table-keys table))
table)
terminator termstr))
(defun process-str (strtable instr)
(let ((tab (copy-table strtable)))
(dolist (x (cl-utilities:split-sequence #\Space instr))
(when (not (gethash x tab))
(setf (gethash x tab) (list x nil))))
(let ((y nil))
(dolist (x (cl-utilities:split-sequence #\Space instr))
(when (and x y)
(push (gethash x tab) (second (gethash y tab))))
(setf y x))
(push '("!TERM" nil) (second (gethash y tab))))
tab))

Loading…
Cancel
Save