From a3e1364c4f4c52732081d86a20e4d7a1869494eb Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 17 Feb 2018 18:34:32 -0800 Subject: [PATCH] named-tuples: make work with bignum indices. --- extra/named-tuples/named-tuples-tests.factor | 6 +++++- extra/named-tuples/named-tuples.factor | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extra/named-tuples/named-tuples-tests.factor b/extra/named-tuples/named-tuples-tests.factor index 3dcf9531ad..7c8d61b8a7 100644 --- a/extra/named-tuples/named-tuples-tests.factor +++ b/extra/named-tuples/named-tuples-tests.factor @@ -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 diff --git a/extra/named-tuples/named-tuples.factor b/extra/named-tuples/named-tuples.factor index 72be384a0e..dac47ce0b3 100644 --- a/extra/named-tuples/named-tuples.factor +++ b/extra/named-tuples/named-tuples.factor @@ -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 ;