ПочатиПочніть безкоштовно

Mutable and typed structs

We've created our type Employee and have created an instance employee to store the details of our CEO. But some of the details will change over time - our CEO might change his name, his age will increase, and he might change his location. We want to keep up-to-date records of our employees, and so we need to be able to update the fields within our employee instance.

We also want to constrain the type of data that is filled out. When our data entry team enters the details of an employee, we want to safeguard against any accidental errors. We want to force:

  • the name to be a string
  • the age to be an integer value
  • the location to be a string

Recall that to create a mutable struct, we use the mutable keyword.

Ця вправа є частиною курсу

Intermediate Julia

Переглянути курс

Інтерактивна практична вправа

Спробуйте виконати цю вправу, доповнивши цей зразок коду.

# Create a mutable struct Employee
____ struct Employee
    name
    location
    age
end
Редагувати та запускати код