factor/core/boxes/boxes.factor

27 lines
583 B
Factor
Raw Normal View History

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