 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel kernel.private math namespaces
 sequences strings words effects generic generic.standard
-classes slots.private combinators ;
+classes slots.private combinators accessors ;
 IN: slots
 
 TUPLE: slot-spec type name offset reader writer ;

        ] [ ] make define-inline
    ] [ 2drop ] if ;

: define-slot-methods ( class slot name -- )
    dup define-changer
    dup define-setter
    3dup define-reader
    define-writer ;

: define-accessors ( class specs -- )
    [
        dup slot-spec-offset swap slot-spec-name
        define-slot-methods
    ] with each ;

: slot-named ( name specs -- spec/f )
    [ slot-spec-name = ] with find nip ;

: reader-word ( name -- word )
    ">>" append (( object -- value )) create-accessor ;

: define-reader ( class slot name decl -- )
    [ reader-word ] dip reader-quot define-slot-word ;

: writer-word ( name -- word )
    "(>>" swap ")" 3append (( value object -- )) create-accessor ;

ERROR: bad-slot-value value object index ;

: writer-quot ( decl -- quot )
    [
        dup object bootstrap-word eq?
        [ drop \ set-slot , ] [
            \ pick ,
            "predicate" word-prop %
            [ [ set-slot ] [ bad-slot-value ] if ] %
        ] if
    ] [ ] make ;

: define-writer ( class slot name decl -- )
    [ writer-word ] dip writer-quot define-slot-word ;

: setter-word ( name -- word )
    ">>" prepend (( object value -- object )) create-accessor ;
