3 ms·
Ada has associative arrays as well. But it will also let you have normal old boring arrays with enums, chars and modular types as indexes.
by Avshalom 11y ago
Ada has associative arrays as well. But it will also let you have normal old boring arrays with enums, chars and modular types as indexes.
- pmontra 11y agoInteresting. Maybe naively, I always assumed that the difference between those two data structures is that an array has integer indices to be mapped trivially to RAM and CPU index registers, and associative arrays are hash tables. I googled this https://en.wikibooks.org/wiki/Ada_Programming/Types/array https://en.wikibooks.org/wiki/Ada_Programming/Types/array and it seems that arrays in Ada can have only discrete indices. Example from there type Character_Counter is array (Character) of Natural; I guess that the compiler maps Character to integers and uses index registers to access RAM. That would be character.ord in Ruby and in many other languages but it's a lower level construct.
- Avshalom 11y agoI can for instance do type throw is (ROCK, PAPER, SCISSORS); type result is (ME, YOU, DRAW); winner : array (throw, throw) of result := ( (DRAW, YOU, ME), (YOU, DRAW, ME), (ME, YOU, DRAW)); YOU = winner(ROCK, PAPER); --would evaluate to true because types are cool.