factor/basis/models/history/history.factor

32 lines
859 B
Factor
Raw Normal View History

! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel models sequences ;
2008-07-04 18:58:37 -04:00
IN: models.history
TUPLE: history < model back forward ;
2008-07-04 18:58:37 -04:00
2008-07-11 02:06:23 -04:00
: reset-history ( history -- history )
V{ } clone >>back
2008-07-11 02:06:23 -04:00
V{ } clone >>forward ; inline
2008-07-04 18:58:37 -04:00
: <history> ( value -- history )
history new-model
reset-history ;
2008-07-04 18:58:37 -04:00
: (add-history) ( history to -- )
2008-08-31 03:51:09 -04:00
swap value>> dup [ swap push ] [ 2drop ] if ;
2008-07-04 18:58:37 -04:00
: go-back/forward ( history to from -- )
2008-09-06 20:13:59 -04:00
[ 2drop ]
2008-12-03 09:46:16 -05:00
[ [ dupd (add-history) ] dip pop swap set-model ] if-empty ;
2008-07-04 18:58:37 -04:00
: go-back ( history -- )
2008-08-31 03:51:09 -04:00
dup [ forward>> ] [ back>> ] bi go-back/forward ;
2008-07-04 18:58:37 -04:00
: go-forward ( history -- )
2008-08-31 03:51:09 -04:00
dup [ back>> ] [ forward>> ] bi go-back/forward ;
2008-07-04 18:58:37 -04:00
: add-history ( history -- )
2008-08-31 03:51:09 -04:00
dup forward>> delete-all
dup back>> (add-history) ;