match-replace ( object pattern1 pattern2 -- result )
Pattern matching

Prev:match-cond ( assoc -- quot )


Vocabulary
match

Inputs
objectan object
pattern1an object
pattern2an object


Outputs
resultan 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


: match-replace ( object pattern1 pattern2 -- result )
[ match [ "Pattern does not match" throw ] unless* ] dip
swap [ replace-patterns ] with-variables ;