Hello,

Here is the current implementation of mismatch:

----------------------------------------------------------------------
: (mismatch) ( seq1 seq2 n -- i )
    [ >r 2dup r> 2nth-unsafe = not ] find drop 2nip ; inline

: mismatch ( seq1 seq2 -- i )
    2dup min-length (mismatch) ;
----------------------------------------------------------------------

If a quotation that is passed to a combinator does more than trivial
stack manipulation, it's a good idea to factor out the body.

----------------------------------------------------------------------
: mismatch-at? ( seq1 seq2 index -- seq1 seq2 ? )
>r 2dup r> 2nth-unsafe = not ;

: mismatch ( seq1 seq2 -- i )
2dup min-length [ mismatch-at? ] find drop 2nip ;
----------------------------------------------------------------------

There's a find-with word. In this case, a find-with2 word would help
clean things up.

----------------------------------------------------------------------
: mismatch-at? ( seq1 seq2 index -- ? ) 2nth-unsafe = not ;

: mismatch ( seq1 seq2 -- i )
2dup min-length [ mismatch-at? ] find-with2 drop ;
----------------------------------------------------------------------

Lastly, in the original implementation, the helper word was named
(mismatch). However, it's actually used by the sequence= word. Let's
give it a non-parenthetical name of mismatch*.

----------------------------------------------------------------------
: mismatch-at? ( seq1 seq2 index -- ? ) 2nth-unsafe = not ;

: mismatch* ( seq1 seq2 n -- i ) [ mismatch-at? ] find-with2 drop ;

: mismatch ( seq1 seq2 -- i ) 2dup min-length mismatch* ;
----------------------------------------------------------------------

Ed

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to