#JuliaTipOfTheDay#JuliaBeginners
2022-11-28

Say you define a type
```
struct Point2D
x::Int
y::Int
end
```
then x and y are the "fields" of this struct. `fieldnames(Point2D)` returns `(:x, :y)`.

If you define `mypt = Point2D(4, 8)`, then
`mypt.x` calls `getproperty(mypt, :x)` (see prev. post),
which by default calls `getfield(mypt, :x)`,
which is automatically defined by #JuliaLang to return `x`'s value.

(contd. from previous: https://julialang.social/@Sundar/109411842573985228
as part 2 of #FieldsAndProperties)

Sundar R :julia: (@[email protected])

#JuliaBeginners #JuliaTipOfTheDay​ 2022-11-26 When you see `foo.bar` in your #JuliaLang code, Julia sees that as the call `getproperty(foo, :bar)`. Let's say you load data into a #DataFrame `df`. When you access `df.Species`, that calls `getproperty(df, :Species)`. DataFrames.jl has a matching method for that call, which returns `df[!, :Species]` i.e. makes it a column access. You can do that for your custom types too! (Useful to understand "fields" before that, a post on those is upcoming.)

JuliaLang