factor/basis/boxes/boxes.factor

29 lines
677 B
Factor
Raw Normal View History

! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-05-14 20:03:07 -04:00
USING: kernel accessors ;
IN: boxes
2008-05-15 01:03:21 -04:00
TUPLE: box value occupied ;
: <box> ( -- box ) box new ;
2008-05-14 20:03:07 -04:00
ERROR: box-full box ;
: >box ( value box -- )
2008-05-15 01:03:21 -04:00
dup occupied>>
[ box-full ] [ t >>occupied value<< ] if ; inline
2008-05-14 20:03:07 -04:00
ERROR: box-empty box ;
: check-box ( box -- box )
dup occupied>> [ box-empty ] unless ; inline
: box> ( box -- value )
2010-04-01 20:05:32 -04:00
check-box [ f ] change-value f >>occupied drop ; inline
: ?box ( box -- value/f ? )
2010-04-01 20:05:32 -04:00
dup occupied>> [ box> t ] [ drop f f ] if ; inline
2008-02-29 20:10:30 -05:00
: if-box? ( box quot -- )
2008-11-29 14:21:40 -05:00
[ ?box ] dip [ drop ] if ; inline