]> gitweb.factorcode.org Git - factor.git/commitdiff
named-tuples: make work with bignum indices.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 18 Feb 2018 02:34:32 +0000 (18:34 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 18 Feb 2018 02:34:32 +0000 (18:34 -0800)
extra/named-tuples/named-tuples-tests.factor
extra/named-tuples/named-tuples.factor

index 3dcf9531adf958d1d331326d27fcada31f4a9c3b..7c8d61b8a7d2af9649d93cfc21bc8beb1e383c15 100644 (file)
@@ -1,4 +1,4 @@
-USING: arrays assocs named-tuples sequences tools.test ;
+USING: arrays assocs math named-tuples sequences tools.test ;
 IN: named-tuples.tests
 
 TUPLE: foo x y z ;
@@ -29,3 +29,7 @@ INSTANCE: foo named-tuple
 { 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
index 72be384a0eb741bc972bca86dd00f8e9fe2f683c..dac47ce0b3d283b8dd7ad12f53918b9c09e22451 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license
 
 USING: accessors assocs classes classes.tuple
-classes.tuple.private kernel sequences sequences.private
+classes.tuple.private kernel math sequences sequences.private
 slots.private ;
 
 IN: named-tuples
@@ -24,9 +24,11 @@ INSTANCE: named-tuple assoc
 
 M: named-tuple length tuple-size ;
 
-M: named-tuple nth-unsafe array-nth ;
+M: named-tuple nth-unsafe
+    [ integer>fixnum ] dip array-nth ;
 
-M: named-tuple set-nth-unsafe set-array-nth ;
+M: named-tuple set-nth-unsafe
+    [ integer>fixnum ] dip set-array-nth ;
 
 M: named-tuple like class-of slots>tuple ;