Paste number 54326: markov

Paste number 54326: markov
Pasted by: fax
6 months, 1 week ago
#lispcafe | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
(defun replacement (string index span with)
  (flet ((before (index) (subseq string 0 index))
         (after (index) (subseq string index))
)

    (concatenate 'string
                 (before index)
                 with
                 (after (+ index span))
)
)
)


(defun markov (rules text)
  (let ((replacement
         (car (sort (remove-if #'null
                               (map 'list #'(lambda (rule)
                                              (list (search (first rule) text)
                                                    (length (first rule))
                                                    (second rule)
)
)

                                    rules
)

                               :key #'car
)

                    #'<
                    :key #'car
)
)
)
)

    (if replacement
        (markov rules (apply #'replacement text replacement))
        text
)
)
)


This paste has no annotations.

Colorize as:
Show Line Numbers

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.