9.0
top
← prev up next →

match-stringπŸ”— i

source code: https://github.com/AlexKnauth/match-string

provides string-append , append , and string as match expanders, and string-append/c , append/c , and string/c as contract constructers.

syntax

( string-append pat...)

(string-append expr...)
pat = match-pattern
| patooo
ooo = ...
| ...+
| ..k
a match expander for matching strings. When it’s not used as a match expander, it behaves like normal rkt:string-append .

Examples:
> (match "abcdef"
[(string-append "abc"s)s])

"def"

> (match "ab cdef"
[(string-append (or "abc""ab c")s)s])

"def"

> (match "cadaddadddr"
[(string-append "c"(and x(or "a""d"))... "r")
x])

'("a" "d" "a" "d" "d" "a" "d" "d" "d")

> (match "abababab"
[(string-append (and los(or "ab""abab"))..3)
los])

'("abab" "ab" "ab")

> (match "abababab"
[(string-append (string-append (and lol"ab")...+)..3)
lol])

'(("ab" "ab") ("ab") ("ab"))

syntax

( append pat...)

(append expr...)
pat = match-pattern
| patooo
ooo = ...
| ...+
| ..k
a match expander for matching lists. When it’s not used as a match expander, it behaves like normal rkt:append .

Examples:
> (match (list 123456)
[(append (list 123)p)p])

'(4 5 6)

> (match '(123. 4)
[(append (list 12)p)p])

'(3 . 4)

> (match '(123. 4)
[(append (list 123)p)p])

4

> (match '(01#:kw-1kw-arg-12#:kw-2kw-arg-234)
[(append (and lol(or (list (?keyword? )_ )(list (not (?keyword? )))))... )
lol])

'((0) (1) (#:kw-1 kw-arg-1) (2) (#:kw-2 kw-arg-2) (3) (4))

> (match '(abababab)
[(append (append (and lolol'(ab))...+)..3)
lolol])

'(((a b) (a b)) ((a b)) ((a b)))

> (match '(123. 4)
[(append (and l(or '(1)'(2)'(3)4))..4)l])

'((1) (2) (3) 4)

syntax

( string pat...)

(string expr...)
pat = match-pattern
| match-patternooo
ooo = ...
| ..k
a match expander for matching string character by character. Whet it’s used as a match expander, it expands to (appstring->list (list pat... )). When it’s not used as a match expander, it behaves like normal rkt:string .

procedure

( string-append/c arg...)flat-contract?

arg:(or/c flat-contract? '...'...+..k?)

procedure

( append/c arg...)flat-contract?

arg:(or/c flat-contract? '...'...+..k?)

procedure

( string/c arg...)flat-contract?

arg:(or/c flat-contract? '...'...+..k?)
behaves like list/c , except over strings. That is, string/c produces a contract that ensures each character of the string fulfils the contract for that position.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /