Multi-dimensional array: Difference between revisions

m
→‎{{header|Factor}}: get-shaped-row-major added to latest version of Factor
(Add Factor)
m (→‎{{header|Factor}}: get-shaped-row-major added to latest version of Factor)
Line 674:
=={{header|Factor}}==
Factor supports multi-dimensional arrays via the <code>arrays.shaped</code> vocabulary. Factor has no widespread syntax for array indexing, so support is provided in the form of words. Both row-major and column-major indexing are available. The underlying data structure of a <code>shaped-array</code> is a flat, contiguous array. <code>arrays.shaped</code> provides an optional word for bounds-checking, <code>shaped-bounds-check</code>, and a word to reshape an array, <code>reshape</code>.
{{works with|Factor|0.99 2020-10-27+}}
<lang factor>USING: accessors arrays.shaped io kernel prettyprint sequences ;
 
: get-shaped-row-major ( seq shaped -- elt )
[ shape calculate-row-major-index ] [ underlying>> nth ] bi ;
 
! Create a 4-dimensional array with increasing elements.
1,808

edits