# vslice

Definition: | sequence res = vslice(sequence source, object column, error_control=0)
Description: | Extract a specified column or vertical slice from a sequence. source: the sequence from which to extract a vertical column. column: positive integer or pair of integers (latter is not Euphoria-compatible). error_control: 0 => crash, integer => return short, sequence => replacement[s]. Returns a sequence or string of at most length(source). The result will be a string if column is an integer and source is either a list of strings or each element extracted happens to be an integer(/character) in the range 0..255.
pwa/p2js: | Supported.
Example: |
    sequence s = {{5,1},
                  {5,2},
                  {5,3},
                  4}
    ?vslice(s,2,1)          -- prints {1,2,3} -- (omitting error_control crashes)
    ?vslice(s,1,1)          -- prints {5,5,5}           --  ""
    ?vslice(s,{1,2},1)      -- prints {{5,1},{5,2},{5,3}} --   ""
    ?vslice(s,{1,2},{1})    -- prints {{5,1},{5,2},{5,3},1} --   ""
(Technically the first two results are binary strings that ? prettifies to look like dword-sequences, as opposed to "\x01\x02\x03", x"010203", "\x05\x05\x05", or x"050505".)
Implementation: | See builtins\vslice.e (an autoinclude) for details of the actual implementation.
See Also: | columnize
Technicalia | For compatibility with Euphoria, error_control can be a non-length-1 sequence of replacements which are taken cyclically, for reasons I cannot even begin to fathom - personally I would just use say {-1} or {"missing"}. I initially planned to write this as a mini wrapper for columnize using the integer column as the second parameter, but it turned out so trivial that doing so would be complete overkill. There is a fair bit of overlap between vslice() and columnize(), this being simpler and slightly faster especially for slices, and that being much better for transposing the whole thing.