pass-by-referenceadacolon-equals

What's the difference between := and => in Ada?


As far as I know, := seems to do an assignation by copy. The operator => seems to do a similar assignation, but is used when assigning a parameter to a member variable of an object.

so...

receivesTheCopy := isBeingCopied

memberVariable => passedParameter

I'm working on someone else's old code and I have a variable reaching a value that I never see explicitly assigned to it with :=. I was thinking that maybe when it is assigned to a memberVariable with => it was passed by reference, and thus the passedParameter variable stayed tied to the memberVariable state.


Solution

  • := is an assignment.

    => has multiple purposes:

    1. Parameter passing: Which formal parameter is passed which argument (if it isn't done by order).
    2. Record and array aggregates: Which field gets which value.
    3. Aspects: Separating aspect names from the expressions they are assigned.

    In neither case it has anything to do with pass-by-reference or pass-by-value.