! create an associative list that maps { { c1 -> c2 } { c2 -> c1 } } : make-swap-assoc ( c1 c2 -- alist ) 2dup swap [ 2array ] 2bi@ 2array ; : swap-string ( s c1 c2 -- s' ) [ make-swap-assoc ?at drop ] 2curry map ; ! Alternatively, use locals and write the following word and then map it over a string. This seems a bit clearer. :: swap-char ( c c1 c2 -- c' ) { { [ c c1 = ] [ c2 ] } { [ c c2 = ] [ c1 ] } [ c ] } cond ; : swap-string ( s c1 c2 -- s' ) [ swap-char ] 2curry map ;