Collections: Difference between revisions

Line 17:
=={{header|11l}}==
11l supports arrays, tuples, dictionaries, sets, and double-ended queues as built-in collection types. See http://11l-lang.org/doc/built-in-types for further details.
=={{header|68000 Assembly}}==
(I'm probably going to use the words "array" and "collection" interchangeably, apologizing in advance here.)
 
Like nearly all data structures in assembly, a collection is just a sequence of values in memory. They need not share the same data type, however mixing byte data with word/long data can cause problems with alignment if the byte data is not correctly padded. Nothing is stopping you from interpreting data the "wrong" way, which can be handy for situations where you need to "deep-copy" an array of bytes and number of elements in that array just happens to be a multiple of 4 (meaning that you can treat the data as longs and copy it more quickly).
 
For collections of data whose elements are more than 4 bytes in size, or have varying lengths (such as strings), it's best to store a collection of pointers to those elements rather than the elements themselves. Reason being, pointers are always 4 bytes (i.e. a "long") on the 68000, regardless of the length of whatever it is they point to. This makes it <b>much easier</b> to find the beginning of a desired string, since you don't have to know each string's length in order to (for example) load the 5th string in the collection
 
In this example, we're creating a collection of strings associated with the vector table of the 68000's CPU. It's not too important what this data represents, it's more to showcase an actual application of the concept of a collection of pointers being more convenient than a collection of actual strings, so don't worry if you don't understand what these strings mean.
 
<lang 68000devpac> dc.l TrapString_Bus
dc.l TrapString_Addr
dc.l TrapString_Illegal
dc.l TrapString_Div0
dc.l TrapString_chk
dc.l TrapString_v
dc.l TrapString_priv
dc.l TrapString_trace
TrapString_Bus:
dc.b "Bus error",255
even
TrapString_Addr:
dc.b "Address error",255
even
TrapString_Illegal:
dc.b "Illegal Instruction",255
even
TrapString_Div0:
dc.b "Divide By Zero",255
even
TrapString_chk:
dc.b "CHK Failure",255
even
TrapString_v:
dc.b "Signed Overflow",255
even
TrapString_priv:
dc.b "Privilege Violation",255
even
TrapString_trace:
dc.b "Tracing",255
even</lang>
 
As mentioned earlier, 68000 Assembly doesn't know (or care) what types of data are stored in an array or collection, although if you try to read from an odd memory address at word or long length your CPU will suffer an alignment fault. The CPU doesn't care what types of data are actually stored in an array. It's the programmer's job to tell the CPU what the data actually means.
 
=={{header|ABAP}}==
1,489

edits