guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

doc list-matches, fold-matches


From: Kevin Ryde
Subject: doc list-matches, fold-matches
Date: Tue, 19 Apr 2005 08:15:15 +1000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

list-matches and fold-matches in ice-9 regexp are exported but not
documented.  They look pretty useful, I think I'll add some words
about them.

(And I think I'll try to clarify how you ask for both regexp/notbol
and regexp/noteol in the regexp-exec flags.  They're a logior if I'm
not mistaken.)


 -- Scheme Procedure: list-matches regexp str [flags]
     Return a list of match structures which are the non-overlapping
     matches of REGEXP in STR.  REGEXP can be either a string pattern
     or a compiled regexp.  FLAGS is as per `regexp-exec' above.

          (map match:substring (list-matches "[a-z]+" "abc 42 def 78"))
          => ("abc" "def")

 -- Scheme Procedure: fold-matches regexp str init proc [flags]
     Apply PROC to the non-overlapping matches of REGEXP in STR to
     build a result.  REGEXP can be either a string pattern or a
     compiled regexp.  FLAGS is as per `regexp-exec' above.

     PROC is called as `(PROC match prev)' where MATCH is a match
     structure and PREV is the previous return from PROC.  For the
     first call PREV is the given INIT parameter.  The final return
     from PROC is the return from `fold-matches'.

     For example to count matches,

          (fold-matches "[a-z][0-9]" "abc x1 def y2" 0
                        (lambda (m count)
                          (1+ count)))
          => 2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]