diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 9f18fd4e66..f3a12d9209 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -1262,6 +1262,17 @@ HELP: shorten "V{ 1 2 3 }" } } ; +HELP: iota +{ $values { "n" integer } { "iota" iota } } +{ $description "Creates an immutable virtual sequence containing the integers from 0 to " { $snippet "n-1" } "." } +{ $examples + { $example + "USING: math.parser sequences ;" + "3 iota [ sq ] map ." + "{ \"0\" \"1\" \"2\" }" + } +} ; + ARTICLE: "sequences-unsafe" "Unsafe sequence operations" "The " { $link nth-unsafe } " and " { $link set-nth-unsafe } " sequence protocol bypasses bounds checks for increased performance." $nl diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 91c9d52404..2a499845bd 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -101,6 +101,16 @@ M: integer nth-unsafe drop ; INSTANCE: integer immutable-sequence +! In the future, this will replace integer sequences +TUPLE: iota { n read-only } ; + +: iota ( n -- iota ) \ iota boa ; inline + +M: iota length n>> ; +M: iota nth-unsafe drop ; + +INSTANCE: iota immutable-sequence + : first-unsafe ( seq -- first ) 0 swap nth-unsafe ; inline