String matching: Difference between revisions

Content added Content deleted
Line 1,425: Line 1,425:
(ends-with str "ghi")
(ends-with str "ghi")


;; function to list positions of pattern inside str
;; find all positions of pattern inside str
(define (positions pattern str)
(define (find-all-pos pattern str)
(let ((idx -1) (pos '()))
(let ((idx -1) (pos '()))
(while (setq idx (find pattern str 0 (+ idx 1)))
(while (setq idx (find pattern str 0 (+ idx 1)))
(push idx pos -1))))
(push idx pos -1))))


(positions "bc" str)</lang>
(find-all-pos "bc" str)</lang>


=={{header|Nimrod}}==
=={{header|Nimrod}}==