What does => mean in Ada?

1.9k Views Asked by At

I understand when and how to use => in Ada, specifically when using the keyword 'others', but I am not sure of its proper name nor how and why it was created. The history and development of Ada is very interesting to me and I would appreciate anyone's insight on this.

3

There are 3 best solutions below

0
On

Stack Overflow isn’t really the place for this kind of question, which is why it's received at least one close vote.

That said, "arrow" has been present in the language since its first version; see ARM83 2.2. See also the Ada 83 Rationale; section 3.5 seems to be the first place where it’s actually used, though not by name.

0
On

=> is called arrow. It is used with any form of parameter, not only with the parameter 'others'.

Section 6.4 of the Ada Reference Manual states:

parameter_association ::= [formal_parameter_selector_name =>] explicit_actual_parameter

explicit_actual_parameter ::= expression | variable_name

A parameter_association is named or positional according to whether or not the formal_parameter_selector_name is specified. Any positional associations shall precede any named associations. Named associations are not allowed if the prefix in a subprogram call is an attribute_reference.

Similarly, array aggregates are described in section 4.3.3

array_aggregate ::= positional_array_aggregate | named_array_aggregate

positional_array_aggregate ::= (expression, expression {, expression}) | (expression {, expression}, others => expression) | (expression {, expression}, others => <>)

named_array_aggregate ::= (array_component_association {, array_component_association})

array_component_association ::= discrete_choice_list => expression | discrete_choice_list => <>

The arrow is used to associate an array index with a specific value or to associate a formal parameter name of a subprogram with the actual parameter.

0
On

As a complement to Jim's answer, on the usage/intuitiveness side: the arrow X => A means in various places of the Ada syntax: value A goes to place X. It is very practical, for instance, to fill an array with an arbitrary cell order. See slide 8 of this presentation for an application with large arrays. Needless to say that the absence of the arrow notation would lead to a heap of bugs in such a case. Sometimes it is just useful for making the associations more readable. You can see it here in action for designing a game level.