Fields: pub and let

Meta: this is also the right place to introduce the field concept, since pub and let declare fields whether they hold a value or a function. The object-context behavior is covered in Objects (type) — link there, don't duplicate.

The pub and let keywords declare fields in the current scope:

These keywords distinguish the expression from Mutation and copy-on-write, which updates an already-declared field.

Two visibilities

What a field is

Forms

pub x = 42                # inferred Int!
pub y: Int! = 100         # explicit type
pub maybe: String = null  # nullable
let secret = "shhh"

Forward references

tl;dr: they work.

.dang files within a directory share a common scope, like in Go

Docstrings

"""
Greets the named user.
"""
pub greet(name: String!): String! {
  `hi, ${name}`
}

Reassignment