This function constructs a procedure which will do the inverse of format when applied to a string.
However, the format-string
can only contain the following
format specifiers, and no modifiers are currently supported:
specifier | meaning |
---|---|
~s | consume as much input as possible and interpret it using read. |
~a | consume as much input as possible, returning it as a string. |
~d | consume a sequence of digit and dot characters and interpret it using string->number. |
The way this function (usually)
works is by using the format string to build
a regular expression, using the regex binding facility to extract
substrings corresponding to the format specifiers in
format-string
. The function returned by this function invokes
the regular expression matcher on it's argument, and, if it matches,
maps the appropriate interpretation procedures (e.g., string->number)
over the substrings.
If the returned function does not find a match, it returns no values.
If the format string contains no
format characters, then an error is signaled by unformat->proc,
since there will be no way to distinguish success from
failure cases of invocations of proc
.
If anywhere?
is #t, then the returned procedure will try to
find something that matches anywhere inside the argument string.
In addition, it will return two additional values (the first two),
which are the start and ending offset in it's given string of
the substring that matched.
Otherwise, by default,
the returned procedure will require an exact match between
the format string and it's argument string.
As usual, you can use bind to capture the multiple values from
proc
.