{ T{ slotty f 1 2 f } } [ H{ { "a" 1 } { "b" 2 } } slotty from-slots ] unit-test
[ H{ { "d" 0 } } slotty new set-slots ] must-fail
+TUPLE: slotty2 { a integer } { b number } c ;
+
+{ T{ slotty2 } } [ H{ } slotty2 from-slots ] unit-test
+{ T{ slotty2 f 1 2 f } } [ H{ { "a" 1 } { "b" 2 } } slotty2 from-slots ] unit-test
+[ H{ { "a" 1 } { "b" "two" } } slotty2 from-slots ] must-fail
+[ H{ { "d" 0 } } slotty2 new set-slots ] must-fail
+
TUPLE: predicate-test ;
C: <predicate-test> predicate-test
[ nip ] [ offset-of-slot ] 2bi slot ;
: set-slot-named ( value name tuple -- )
- [ nip ] [ offset-of-slot ] 2bi set-slot ;
+ [ nip ] [
+ 2dup class-of all-slots slot-named
+ [ 2nip pick over check-slot-value offset>> ] [ no-slot ] if*
+ ] 2bi set-slot ;
: set-slots ( assoc tuple -- )
[ swapd set-slot-named ] curry assoc-each ; inline
[ array-nth ] curry map ;
: check-slots ( seq class -- seq class )
- [ ] [
- 2dup all-slots [
- class>> 2dup instance?
- [ 2drop ] [ bad-slot-value ] if
- ] 2each
- ] if-bootstrapping ; inline
+ [ ] [ 2dup all-slots [ check-slot-value ] 2each ] if-bootstrapping ; inline
: pad-slots ( seq class -- seq' class )
[ all-slots ] keep 2over 2length 2dup > [