From 4a14bd407d7434ab9f233a20a86e8fa8dd94bc88 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 25 Jul 2012 18:24:43 -0700 Subject: [PATCH] core: Use integer>fixnum instead of >fixnum for ``nth`` and other sequence operations. Fixes #581. --- core/arrays/arrays.factor | 4 ++-- core/sequences/sequences-tests.factor | 7 +++++-- core/sequences/sequences.factor | 6 +++--- core/strings/strings.factor | 4 ++-- core/vectors/vectors.factor | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/arrays/arrays.factor b/core/arrays/arrays.factor index 21f9c239fd..085a6a582b 100644 --- a/core/arrays/arrays.factor +++ b/core/arrays/arrays.factor @@ -5,8 +5,8 @@ IN: arrays M: array clone (clone) ; inline M: array length length>> ; inline -M: array nth-unsafe [ >fixnum ] dip array-nth ; inline -M: array set-nth-unsafe [ >fixnum ] dip set-array-nth ; inline +M: array nth-unsafe [ integer>fixnum ] dip array-nth ; inline +M: array set-nth-unsafe [ integer>fixnum ] dip set-array-nth ; inline M: array resize resize-array ; inline M: array equal? over array? [ sequence= ] [ 2drop f ] if ; M: object new-sequence drop 0 ; inline diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index c1bc96c259..a4167bfcbd 100644 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -1,6 +1,7 @@ USING: arrays byte-arrays kernel math math.order math.parser namespaces sequences kernel.private sequences.private strings -sbufs tools.test vectors assocs generic vocabs.loader ; +sbufs tools.test vectors assocs generic vocabs.loader +generic.single ; IN: sequences.tests [ "empty" ] [ { } [ "empty" ] [ "not empty" ] if-empty ] unit-test @@ -213,7 +214,9 @@ unit-test [ V{ "a" "b" } V{ } ] [ { "X" "a" "b" } { "X" } drop-prefix [ >vector ] bi@ ] unit-test -[ 1 ] [ 0.5 { 1 2 3 } nth ] unit-test +[ 0.5 10 iota nth ] [ no-method? ] must-fail-with +[ 0.5 { 1 2 3 } nth ] [ no-method? ] must-fail-with +[ 0.5 "asdfasdf" nth ] [ no-method? ] must-fail-with ! Pathological case [ "ihbye" ] [ "hi" "bye" append ] unit-test diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 67e4440303..dd6774011e 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -106,7 +106,7 @@ TUPLE: iota { n integer read-only } ; : iota ( n -- iota ) \ iota boa ; inline M: iota length n>> ; inline -M: iota nth-unsafe drop ; inline +M: iota nth-unsafe drop integer>fixnum ; inline INSTANCE: iota immutable-sequence @@ -634,7 +634,7 @@ ERROR: assert-sequence got expected ; fixnum swap [ + integer>fixnum swap [ [ -2 fixnum-shift-fast ] [ 5 fixnum-shift-fast ] bi fixnum+fast fixnum+fast ] keep fixnum-bitxor ; inline @@ -845,7 +845,7 @@ PRIVATE> #! We can't use case here since combinators depends on #! sequences pick length dup 0 3 between? [ - >fixnum { + integer>fixnum { [ drop nip ] [ 2drop first ] [ [ drop first2 ] dip call ] diff --git a/core/strings/strings.factor b/core/strings/strings.factor index 1f266e2e47..f0e589b7db 100644 --- a/core/strings/strings.factor +++ b/core/strings/strings.factor @@ -63,11 +63,11 @@ M: string length length>> ; inline M: string nth-unsafe - [ >fixnum ] dip string-nth ; inline + [ integer>fixnum ] dip string-nth ; inline M: string set-nth-unsafe dup reset-string-hashcode - [ >fixnum ] [ >fixnum ] [ ] tri* set-string-nth ; inline + [ integer>fixnum ] [ integer>fixnum ] [ ] tri* set-string-nth ; inline M: string clone (clone) [ clone ] change-aux ; inline diff --git a/core/vectors/vectors.factor b/core/vectors/vectors.factor index 4bbc787294..e9def85fbb 100644 --- a/core/vectors/vectors.factor +++ b/core/vectors/vectors.factor @@ -18,7 +18,7 @@ M: vector like ] unless ; inline M: vector new-sequence - drop [ f ] [ >fixnum ] bi vector boa ; inline + drop [ f ] [ integer>fixnum ] bi vector boa ; inline M: vector equal? over vector? [ sequence= ] [ 2drop f ] if ; -- 2.34.1