liveBook · Manning

Attribute

As explained in Julia as a Second Language

A field is a named component declared within a composite type and stored in each value of that type.

A field is a named component declared in a composite type; every instance of that type stores values for its fields. In Julia, field type annotations specify what each component can hold. Unlike dictionary entries, fields are fixed by the type, and instances cannot add or remove them at runtime. section 7.1 section 18.4

Listing 7.1 Definition of a composite type
struct Archer
    name::String   #1
    health::Int    #2
    arrows::Int    #3
end

An Archer type declares three fields, each with a name and a type. section 7.1

Reading fields

An Archer instance stores a name, health, and arrow count. Read a value with dot access, as in robin.name or robin.arrows. section 7.1

How Julia as a Second Language covers it

How deep it goes
Defines fields through typed struct examples and explains their fixed layout, without detailing compiler internals.
Examples
Uses Archer records with name, health, and arrows, plus a Vec2D type with coordinate fields.
What you can do after
Build from scratch a composite type with named, typed fields and read instance values through dot access.
How it connects
Connects fields to composite types, type annotations, instances, dictionaries, and just-in-time compilation.

Also explained in

Compare how 26 books explain attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.