Pattern Matching for Ports
port-match
1 Extending port-match
define-port-match-expander
prop:  port-match-expander
port-match-expander?
8.17.0.6

Pattern Matching for Ports🔗ℹ

 (require port-match/base) package: port-match

syntax

(port-match in-port clause ...)

 
clause = [pat body ...+]
Like match, but matches against values read from in-port.

pat must be a head pattern, which may be specified as follows:

  • (byte tail ...) matches a single byte.

  • (bytes amt tail ...) matches a sequence of exactly amt bytes.

  • (char tail ...) matches a single UTF-8 character.

  • (string len tail ...) matches a sequence of exactly len characters.

  • (regexp pattern tail ...) matches a sequence of characters or bytes which match pattern. The pattern must match immediately to count as a match (as if it began with ^).

  • eof matches end-of-file.

  • (seq head ...) matches each head in sequence.

Head patterns recognize one or more datums, which may be matched against tail patterns:

  • (app proc tail) calls proc with the matched datum, and matches the result against tail.

  • (? proc tail ...) matches only if proc returns true when applied to the matched datum.

  • id binds id to the matched datum.

Patterns may be combined as follows:

  • (and pat ...) matches only if every pat matches.

  • (or pat ...) matches if at least one pat matches.

  • _ matches anything.

1 Extending port-match🔗ℹ

syntax

(define-port-match-expander id proc-expr)

value

prop:port-match-expander : struct-type-property?

procedure

(port-match-expander? v)  boolean?

  v : any/c
Predicate for values which implement prop:port-match-expander.