--- /dev/null
+John Benediktsson
--- /dev/null
+USING: assocs classes.mixin help.markup help.syntax named-tuples
+sequences ;
+
+HELP: named-tuple
+{ $class-description "A " { $link mixin-class } " that allows you to treat a tuple as both a " { $link sequence } " and an " { $link assoc } "." } ;
--- /dev/null
+USING: arrays assocs classes.tuple kernel math named-tuples
+sequences tools.test ;
+IN: named-tuples.tests
+
+TUPLE: foo x y z ;
+
+INSTANCE: foo named-tuple
+
+{ { f f f } } [ T{ foo } >array ] unit-test
+{ { 1 f f } } [ T{ foo f 1 } >array ] unit-test
+{ { 1 2 f } } [ T{ foo f 1 2 } >array ] unit-test
+{ { 1 2 3 } } [ T{ foo f 1 2 3 } >array ] unit-test
+
+{ T{ foo } } [ { } T{ foo } like ] unit-test
+{ T{ foo f 1 } } [ { 1 } T{ foo } like ] unit-test
+{ T{ foo f 1 2 } } [ { 1 2 } T{ foo } like ] unit-test
+{ T{ foo f 1 2 3 } } [ { 1 2 3 } T{ foo } like ] unit-test
+
+{ { { "x" f } { "y" f } { "z" f } } } [ T{ foo } >alist ] unit-test
+{ { { "x" 1 } { "y" f } { "z" f } } } [ T{ foo f 1 } >alist ] unit-test
+{ { { "x" 1 } { "y" 2 } { "z" f } } } [ T{ foo f 1 2 } >alist ] unit-test
+{ { { "x" 1 } { "y" 2 } { "z" 3 } } } [ T{ foo f 1 2 3 } >alist ] unit-test
+
+{ f } [ T{ foo } "x" of ] unit-test
+{ f } [ T{ foo } "y" of ] unit-test
+{ f } [ T{ foo } "z" of ] unit-test
+
+{ f f } [ "not found" T{ foo f 1 2 3 } at* ] unit-test
+
+{ T{ foo f "x" 2 3 } } [ T{ foo f 1 2 3 } "x" dup pick set-at ] unit-test
+
+[ 1 "not found" T{ foo f 1 2 3 } set-at ] [ no-slot? ] must-fail-with
+
+{ 1 } [ T{ foo f 1 2 3 } "x" of ] unit-test
+{ 2 } [ T{ foo f 1 2 3 } "y" of ] unit-test
+{ 3 } [ T{ foo f 1 2 3 } "z" of ] unit-test
+
+{ 1 } [ 0 >bignum T{ foo f 1 2 3 } nth ] unit-test
+{ 2 } [ 1 >bignum T{ foo f 1 2 3 } nth ] unit-test
+{ 3 } [ 2 >bignum T{ foo f 1 2 3 } nth ] unit-test
--- /dev/null
+! Copyright (C) 2018 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors assocs classes classes.tuple
+classes.tuple.private kernel math sequences sequences.private
+slots.private ;
+
+IN: named-tuples
+
+MIXIN: named-tuple
+
+M: named-tuple assoc-size tuple-size ;
+
+M: named-tuple at*
+ [ nip ] [ ?offset-of-slot ] 2bi [ slot t ] [ drop f f ] if* ;
+
+M: named-tuple set-at set-slot-named ;
+
+M: named-tuple >alist
+ dup class-of all-slots
+ [ [ offset>> slot ] [ name>> ] bi swap ] with { } map>assoc ;
+
+INSTANCE: named-tuple assoc
+
+M: named-tuple length tuple-size ;
+
+M: named-tuple nth-unsafe
+ [ integer>fixnum ] dip array-nth ;
+
+M: named-tuple set-nth-unsafe
+ [ integer>fixnum ] dip set-array-nth ;
+
+M: named-tuple like class-of slots>tuple ;
+
+INSTANCE: named-tuple sequence
+
--- /dev/null
+Use tuples like both sequences and assocs
--- /dev/null
+collections
+++ /dev/null
-John Benediktsson
+++ /dev/null
-USING: assocs classes.mixin help.markup help.syntax named-tuples
-sequences ;
-
-HELP: named-tuple
-{ $class-description "A " { $link mixin-class } " that allows you to treat a tuple as both a " { $link sequence } " and an " { $link assoc } "." } ;
+++ /dev/null
-USING: arrays assocs classes.tuple kernel math named-tuples
-sequences tools.test ;
-IN: named-tuples.tests
-
-TUPLE: foo x y z ;
-
-INSTANCE: foo named-tuple
-
-{ { f f f } } [ T{ foo } >array ] unit-test
-{ { 1 f f } } [ T{ foo f 1 } >array ] unit-test
-{ { 1 2 f } } [ T{ foo f 1 2 } >array ] unit-test
-{ { 1 2 3 } } [ T{ foo f 1 2 3 } >array ] unit-test
-
-{ T{ foo } } [ { } T{ foo } like ] unit-test
-{ T{ foo f 1 } } [ { 1 } T{ foo } like ] unit-test
-{ T{ foo f 1 2 } } [ { 1 2 } T{ foo } like ] unit-test
-{ T{ foo f 1 2 3 } } [ { 1 2 3 } T{ foo } like ] unit-test
-
-{ { { "x" f } { "y" f } { "z" f } } } [ T{ foo } >alist ] unit-test
-{ { { "x" 1 } { "y" f } { "z" f } } } [ T{ foo f 1 } >alist ] unit-test
-{ { { "x" 1 } { "y" 2 } { "z" f } } } [ T{ foo f 1 2 } >alist ] unit-test
-{ { { "x" 1 } { "y" 2 } { "z" 3 } } } [ T{ foo f 1 2 3 } >alist ] unit-test
-
-{ f } [ T{ foo } "x" of ] unit-test
-{ f } [ T{ foo } "y" of ] unit-test
-{ f } [ T{ foo } "z" of ] unit-test
-
-{ f f } [ "not found" T{ foo f 1 2 3 } at* ] unit-test
-
-{ T{ foo f "x" 2 3 } } [ T{ foo f 1 2 3 } "x" dup pick set-at ] unit-test
-
-[ 1 "not found" T{ foo f 1 2 3 } set-at ] [ no-slot? ] must-fail-with
-
-{ 1 } [ T{ foo f 1 2 3 } "x" of ] unit-test
-{ 2 } [ T{ foo f 1 2 3 } "y" of ] unit-test
-{ 3 } [ T{ foo f 1 2 3 } "z" of ] unit-test
-
-{ 1 } [ 0 >bignum T{ foo f 1 2 3 } nth ] unit-test
-{ 2 } [ 1 >bignum T{ foo f 1 2 3 } nth ] unit-test
-{ 3 } [ 2 >bignum T{ foo f 1 2 3 } nth ] unit-test
+++ /dev/null
-! Copyright (C) 2018 John Benediktsson
-! See http://factorcode.org/license.txt for BSD license
-
-USING: accessors assocs classes classes.tuple
-classes.tuple.private kernel math sequences sequences.private
-slots.private ;
-
-IN: named-tuples
-
-MIXIN: named-tuple
-
-M: named-tuple assoc-size tuple-size ;
-
-M: named-tuple at*
- [ nip ] [ ?offset-of-slot ] 2bi [ slot t ] [ drop f f ] if* ;
-
-M: named-tuple set-at set-slot-named ;
-
-M: named-tuple >alist
- dup class-of all-slots
- [ [ offset>> slot ] [ name>> ] bi swap ] with { } map>assoc ;
-
-INSTANCE: named-tuple assoc
-
-M: named-tuple length tuple-size ;
-
-M: named-tuple nth-unsafe
- [ integer>fixnum ] dip array-nth ;
-
-M: named-tuple set-nth-unsafe
- [ integer>fixnum ] dip set-array-nth ;
-
-M: named-tuple like class-of slots>tuple ;
-
-INSTANCE: named-tuple sequence
-
+++ /dev/null
-Use tuples like both sequences and assocs
+++ /dev/null
-collections