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