 : history-recall ( history i -- )
     [ [ elements>> empty? ] keep ] dip '[
         _
-        [ save-history drop ]
+        [ save-history ]
         [ _ change-history-index ]
         [ update-document ]
         tri

: <history> ( document -- history )
    V{ } clone 0 history boa ;

<PRIVATE

: save-history ( history -- input )
    [ document>> doc-string [ <input> ] [ empty? ] bi ] keep
    '[ [ _ [ index>> ] [ elements>> ] bi set-nth ] keep ] unless ;

: update-document ( history -- )
    [ [ index>> ] [ elements>> ] bi nth string>> ]


PRIVATE>

: history-recall-previous ( history -- )
    -1 history-recall ;

