(define-module (mutate) #:use-module (srfi srfi-1) #:export (deletes transposes replaces inserts)) ;; see https://norvig.com/spell-correct.html ;; this is a translation of that from python ;; to guile (define (deletes word) (define (deletes-helper word splits result) (if (null? splits) result (let* ((split (car splits)) (tail (cdr split))) (if (zero? (string-length tail)) (deletes-helper word (cdr splits) result) (deletes-helper word (cdr splits) (append result (list (string-append (car split) (substring tail 1))))))))) (deletes-helper word (splits word) '())) (define (transposes word) #t) (define (replaces word) #t) (define (inserts word) #t) (define (splits word) "Given WORD, returns a list of pairs of all possible splits: 'six' -> (('' . 'six') ('s' . 'ix') ('si' . 'x') ('six' . ''))" (map (lambda (s) (cons (substring word 0 s) (substring word s))) (iota (1+ (string-length word)))))