Arrays: Difference between revisions
Content added Content deleted
Line 7,682: | Line 7,682: | ||
=> hello |
=> hello |
||
=={{header|Transd}}== |
|||
Arrays in Transd are implemented in the form of dynamic containers: Vectors. Vector is |
|||
a type parameterized container (also known as "generic"), that is a Vector object can |
|||
only hold values of a single type. |
|||
Vectors can be created as empty containers, or they can be initialized with some values at the time of creation. |
|||
<lang Scheme>module1 : { |
|||
v1: Vector<Int>(), |
|||
v2: Vector<String>(), |
|||
v3: Vector<Int>([1,2,3,4]), |
|||
v4: Vector<String>(["one","two","three"]), |
|||
// the type of vector values can automaticaly deduced |
|||
v5: [1.0, 2.5, 8.6], // Vector<Double> |
|||
v6: ["one","two","three"] // Vector<String> |
|||
}</lang> |
|||
Individual elements in a vector can be read, appended, and deleted. |
|||
<lang Scheme>(with v [1,2,3] |
|||
(textout (get v 1)) // <= 2 |
|||
(erase v 1) |
|||
(textout v) // <= [1, 3] |
|||
(append v 7) |
|||
(textout v) // <= [1, 3, 7] |
|||
)</lang> |
|||
All standard container operations can be applied to vectors: |
|||
<lang Scheme>(with v [3,1,5,2,4] |
|||
(textout (reverse v)) // <= [4, 2, 5, 1, 3] |
|||
(textout (sort v)) // <= [1, 2, 3, 4, 5] |
|||
(textout (shuffle v)) // <= [5, 3, 4, 1, 2] |
|||
)</lang> |
|||
=={{header|TXR}}== |
=={{header|TXR}}== |