Guile Present

(present util)


 Utility procedures and macros.


[Special Form]

Match a string against a regular expression, binding lexical variables to the various parts of the match.

vars is a list of names to which to bind the parts of the match. The first variable of the list will be bound to the entire match, so the number of variables needed will be equal to the number of open parentheses (`(') in the pattern, plus one for the whole match.

consequent is executed if the given expression str matches regex. If the string does not match, alternate will be executed if present. If alternate is not present, the result of match-bind is unspecified.

Here is a short example:

 (define (star-indent line)
   "Returns the number of spaces until the first
    star (`*') in the input, or #f if the first
    non-space character is not a star."
   (match-bind "^( *)\*.*$" line (_ spaces)
               (string-length spaces)

match-bind compiles the regular expression regex at macro expansion time. For this reason, regex must be a string literal, not an arbitrary expression.