(module kmp-tableau (export (kmp:tableau Motif))) (define (kmp:tableau Motif) (let* ((L-motif (string-length Motif)) (Tpref (make-vector (+ L-motif 1) 0)) (i 0) (j -1)) (vector-set! Tpref 0 j) (let boucle ((c #a000)) ;; le caractère nul (print Tpref) (cond ((= i L-motif) 'fini) ((char=? c (string-ref Motif i)) (vector-set! Tpref (+ i 1) (+ j 1)) (set! j (+ j 1)) (set! i (+ i 1))) ((> j 0) (set! j (vector-ref Tpref j))) (else (vector-set! Tpref (+ i 1) 0) (set! i (+ i 1)) (set! j 0))) (if (< i L-motif) (boucle (string-ref Motif j)) Tpref))))