Assignment shares a reference, it does not copy

The complete source of operators_assignment.ek9, compiled by the EK9 compiler. Shown on operators.html.

#!ek9
defines module site.operators.assignment

  defines record

    Address
      country as String: String()

      default Address()

      Address()
        -> country as String
        this.country: country

      default operator ?

  defines program

    Assignment()
      stdout <- Stdout()

      checkAddr <- Address() //a new empty address, so it is unset
      myAddress <- Address() //assigned to a new empty address

      myAddress.country: "UK" //assuming the Address was a record with a country field

      checkAddr := myAddress
      //Both myAddress and checkAddr reference the same address
      //But the data has not been copied

      //Change the country in either checkAddr or myAddress and value will alter
      checkAddr.country = "US"
      //myAddress.country is now also "US"

      anAddress <- Address() //a new empty address, so it is unset

      anAddress :=? myAddress
      //anAddress is only assigned if it was unset or had no memory allocated; as above.

      anAddress :=? Address("US")
      //anAddress would not have been assign above as it already has a valid Address value

      stdout.println(myAddress.country)
      stdout.println(anAddress.country)

Download operators_assignment.ek9

Output

US
US