1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors ;
6 TUPLE: box value occupied ;
8 : <box> ( -- box ) box new ;
12 : >box ( value box -- )
14 [ box-full ] [ t >>occupied value<< ] if ; inline
16 ERROR: box-empty box ;
18 : check-box ( box -- box )
19 dup occupied>> [ box-empty ] unless ; inline
23 : box-unsafe> ( box -- value )
24 [ f ] change-value f >>occupied drop ; inline
28 : box> ( box -- value )
29 check-box box-unsafe> ; inline
31 : ?box ( box -- value/f ? )
32 dup occupied>> [ box-unsafe> t ] [ drop f f ] if ; inline
34 : if-box? ( box quot: ( value -- ) -- )
35 [ ?box ] dip [ drop ] if ; inline