diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index 3912211872..34bf2abdba 100644 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -313,6 +313,7 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ; [ V{ 0 3 } ] [ "A" { "A" "B" "C" "A" "D" } indices ] unit-test [ "asdf" iota ] must-fail +[ -1 iota ] must-fail [ T{ iota { n 10 } } ] [ 10 iota ] unit-test [ 0 ] [ 10 iota first ] unit-test @@ -374,4 +375,3 @@ USE: make { 255 0 175 } } [ { 0 0 255 } distance ] infimum-by ] unit-test - diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 37ffdb34dc..4765de956b 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -104,7 +104,10 @@ INSTANCE: f immutable-sequence ! Integer sequences TUPLE: iota { n integer read-only } ; -: iota ( n -- iota ) \ iota boa ; inline +ERROR: non-negative-integer-expected n ; + +: iota ( n -- iota ) + dup 0 < [ non-negative-integer-expected ] when \ iota boa ; inline M: iota length n>> ; inline M: iota nth-unsafe drop ; inline