PasteRack.org
Paste # 32256
2020-11-19 14:08:04

Fork as a new paste.

Paste viewed 406 times.


Embed:

  1. #lang racket
  2.  
  3.  
  4. (define (match t p)
  5.   (define n-t (string-length t))
  6.   (define n-p (string-length p))
  7.   (let loop
  8.     ((i-t 0)
  9.      (i-p 0))
  10.     (cond
  11.       ((> i-p (- n-p 1))
  12.        i-t)
  13.       ((> i-t (- n-t n-p))
  14.        #f)
  15.       ((eq? (string-ref t (+ i-t i-p)) (string-ref p i-p))
  16.        (loop i-t (+ i-p 1)))
  17.       (else
  18.        (loop (+ i-t 1) 0)))))
  19.  
  20. (match "abcdefg" "fg")

=>