Tuple code cleanups

slava 2006-05-20 06:23:21 +00:00
parent 8cdc10abdb
commit c0e3553dd2
2 changed files with 16 additions and 7 deletions

View File

@ -58,15 +58,18 @@ PREDICATE: word tuple-class "tuple-size" word-prop ;
tuple-class? [ "Not a tuple class" throw ] unless ;
: define-constructor ( word class def -- )
over check-tuple-class >r [
dup literalize , "tuple-size" word-prop , \ make-tuple ,
] [ ] make r> append define-compound ;
pick reset-generic
swap dup check-tuple-class [
dup literalize ,
"tuple-size" word-prop ,
\ make-tuple , %
] [ ] make define-compound ;
: default-constructor ( tuple -- )
[ create-constructor ] keep dup [
"slots" word-prop 1 swap tail-slice <reversed>
[ peek unit , \ keep , ] each
] [ ] make define-constructor ;
[ create-constructor ] keep
dup "slots" word-prop unclip drop <reversed>
[ [ tuck ] swap peek add ] map concat >quotation
define-constructor ;
: define-tuple ( tuple slots -- )
2dup check-shape

View File

@ -111,3 +111,9 @@ TUPLE: size-test a b c d ;
T{ size-test } array-capacity
size-test "tuple-size" word-prop =
] unit-test
GENERIC: <yo-momma>
TUPLE: yo-momma ;
[ f ] [ \ <yo-momma> generic? ] unit-test