Pyli/Methods/Sequence
Contents
Sequences
These are useful for any kind of type that has contents, such as strings, vectors, and dicts.
- (empty? seq): Return True if a contains no items, False otherwise.
- (length seq): Return the number of items in a.
- (el seq index): Return the item of seq at the index.
- (sub seq start [end]): Return the sub sequence of the seq starting from start to end.
These will generate sequences.
- (range x [y [z]]):
- (range x): 0 to (x-1)
- (range x y): x to (y-1)
- (range x y z): x to (y-1) step z
- (from x [step z]): Starts at x and goes on forever.
- (to x [step z]): Starts at 0 and goes on to x-1.
- (from x to y [step z]): x to (y-1) step z.
iter-fn
(iter-fn body ...)
iter-fn returns an iterator. (iter-fn.iter) returns itself.)
Calling (iter-fn.next) will call the body statements, one at a time, in the lexical environment they were defined in. The result is returned. It a stop-iteration is signalled, then that will be passed on.
iter-named-fn
(iter-named-fn name body ...)
Like iter-fn, but the next method has a name of 'name'.
map
- (map fn a)
Returns an iterator that will apply fn to a.next before yielding it.
zip
- (zip a b ...)
Returns an iterator that will yield (a.next b.next ...).