1 ! Copyright (C) 2008 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: accessors kernel models sequences ;
\r
6 TUPLE: history < model back forward ;
\r
8 : reset-history ( history -- history )
\r
10 V{ } clone >>forward ; inline
\r
12 : <history> ( value -- history )
\r
16 : (add-history) ( history to -- )
\r
17 swap model-value dup [ swap push ] [ 2drop ] if ;
\r
19 : go-back/forward ( history to from -- )
\r
22 [ >r dupd (add-history) r> pop swap set-model ] if ;
\r
24 : go-back ( history -- )
\r
25 dup history-forward over history-back go-back/forward ;
\r
27 : go-forward ( history -- )
\r
28 dup history-back over history-forward go-back/forward ;
\r
30 : add-history ( history -- )
\r
31 dup history-forward delete-all
\r
32 dup history-back (add-history) ;
\r