Handbook
Glossary
match-replace ( object pattern1 pattern2 -- result )
Pattern matching
Prev:
match-cond ( assoc -- quot )
Vocabulary
match
Inputs
object
an
object
pattern1
an
object
pattern2
an
object
Outputs
result
an
object
Word description
Matches the
object
against
pattern1
. The pattern match variables in
pattern1
are assigned the values from the matching
object
. These are then replaced into the
pattern2
pattern match variables.
Examples
USING: match prettyprint ; IN: scratchpad MATCH-VARS: ?a ?b ; { 1 2 } { ?a ?b } { ?b ?a } match-replace .
{ 2 1 }
See also
match-cond
,
MATCH-VARS:
Definition
USING:
kernel
namespaces
;
IN:
match
:
match-replace
( object pattern1 pattern2 -- result )
[
match
[
"Pattern does not match"
throw
]
unless*
]
dip
swap
[
replace-patterns
]
with-variables
;