Add iota virtual sequence which will eventually replace integers-as-sequences

db4
Slava Pestov 2009-01-09 21:35:49 -06:00
parent a743e6a08b
commit a977691d82
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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