 (def word-pattern #"\S+")
 (def generated-sentence-length 30)
 (def prefix-length 3)
+(def retries 5)
 
 (def table (ref {}))
 (def starters (ref []))

            word
            (recur (rest c) (- i weight)))))
(defn pick-next-word [prefix t]
    (when-let [candidates (t prefix)]
        (select candidates
            (rand-int (reduce + 0 (vals candidates))))))
(defn further-stream-of-shite [prefix t]
    (lazy-seq
        (when-let [c (pick-next-word prefix t)]
            (cons c (further-stream-of-shite (concat (rest prefix) [c]) t)))))
(defn stream-of-shite [prefix t]
    (concat prefix (further-stream-of-shite prefix t)))
(defn generate-sentence []
    (take generated-sentence-length (stream-of-shite
        (nth @starters (rand-int (count @starters)))
        @table)))

(defn value-or-default [value default]
    (if (nil? value) default value))

                (ref-set starters (conj @starters (take prefix-length words)))))))
(defn log-sentence! [message]
    (with-open [out (writer corpus-file :append true)]
        (.write out (str message "\n")))
    (update-message! message))

(defn -main
    [& args]
    (let [bot (connect
            (create-irc {
                :name bot-nick
                :server irc-server
                :fnmap {
                    :on-message (fn [{:keys [nick channel message irc]}]
                        (log-sentence! message)
                        (if (and (not (= nick (:name @irc))) (.contains message (:name @irc)))
                            (send-message irc channel
                                (join " " (generate-sentence)))))
                }
            })
            :channels irc-channels)]
