Hello,

Here's the current implementation of repeat:

----------------------------------------------------------------------

: (repeat) ( from to quot -- )
    pick pick >= [
        3drop
    ] [
        [ swap >r call 1+ r> ] keep (repeat)
    ] if ; inline

: repeat ( n quot -- ) 0 -rot (repeat) ; inline

----------------------------------------------------------------------

To understand how repeat works, you really have to work through what
(repeat) is doing. Here's an alternative version which is "self
documenting" and is just as fast:

: alt-repeat ( n quot -- )
repeat-done? [ repeat-done ] [ repeat-iterate alt-repeat ] if ;

The helper words are:

----------------------------------------------------------------------

: repeat-done? ( n quot -- n quot ? ) over 0 = ;

: repeat-done ( n quot -- ) 2drop ;

: repeat-iterate ( n quot -- n quot ) dup >r call 1- r> ;

----------------------------------------------------------------------

Again, in this style of design, all the stack shuffling is
factored out into helper words.

It's true that in this alternate version there are more words. But,
according to masters of the art of stack programming, more and smaller
words are better than less and longer words. So, I'm going with that
principle here.

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