Paste: replace-pairs

Author: hsuh
Mode: factor
Date: Thu, 14 Jan 2010 12:55:34
Plain Text |
The following doesn't work, the string is returned without changes from replace-pairs... any help? 

BTW, I really hated writing these functions in factor, they don't feel nice. (Had to go back to elisp to finish my task :( )

: replace-string ( string old new -- string ) 
    [ split1-slice ] dip over
    [ swap 3append ] 
    [ 2drop ] if ;

:: replace-pairs ( string from to -- string )
    from to
    [ 
        [ string ] 2dip
        replace-string
        :> string
    ] 2each string ;

Annotation: fixed

Author: hsuh
Mode: factor
Date: Thu, 14 Jan 2010 15:00:04
Plain Text |
: replace-string ( string old new -- string ) 
    [ split1-slice ] dip over
    [ glue ] [ 2drop ] if ;

: replace-pairs ( string from to -- string )
    [ replace-string ] 2each ;    

New Annotation

Summary:
Author:
Mode:
Body: