Foundations Syntax and Atoms Lesson 03
Atoms and intent
Mental Model
SJON keeps value kinds distinct. A value does not forget whether you wrote it as a string, symbol, keyword, number, boolean, or nil.
Use this authoring rule:
- Keyword - names a slot or acts as a flag:
:name,:ortho. - Symbol - names something the schema resolves:
ortho,mask,parent.transform,C#4,+. - String - carries opaque text:
"intro","black","hello.wgsl". - Boolean - carries truth:
true,false. - Nil - carries explicit absence:
nil. - Number - carries numeric magnitude, optionally with a unit suffix.
Identifiers are case-sensitive. circle, Circle, and CIRCLE are
different heads or symbols.
Identifiers can include letters, digits after the first character,
operator characters, _, -, ., /, and a few other punctuation
characters. # is allowed inside an identifier, but not as the
first character. That makes natural sharp spellings such as C#4 and
F#m valid symbols for plugins that model musical note names. A token
starting with # is reserved for block comments, so #note is not a
symbol.
Worked Example
(camera
:ortho
:projection ortho
:zoom 2
:label "main camera"
:enabled true
:debug nil)
Read the intent:
:orthois a positional flag.:projection orthouses a symbol value. A schema can constrain it to a member set such asortho | perspective.:zoom 2uses a number.:label "main camera"uses a string because this is free text.:enabled trueuses a boolean.:debug nilexplicitly says the slot has no value.
Do not write this when the slot expects a symbol:
(camera :projection :ortho)
That does not create projection = :ortho. The keyword pairing rule
will treat both keywords as flags. Section 5 covers this in detail.
Exercises
Choose the intended value kind for each slot:
- A user-visible title:
"intro"orintro? - A closed projection mode:
"ortho",ortho, or:ortho? - A boolean toggle:
"false"orfalse? - An absent optional value:
"nil"ornil? - A form flag with no payload:
:orthoorortho?
Repair each broken example:
(scene :name intro)
If :name is free-form text, repair with a string:
(scene :name "intro")
(camera :projection "ortho")
If :projection is a symbol member set, repair with a symbol:
(camera :projection ortho)
(placeholder :enabled "false" :data "nil")
If the slots expect a boolean and nil, repair the atoms:
(placeholder :enabled false :data nil)
Mastery Check
-
Which value kind should you use for a filename?
-
Which value kind should you use for a closed enum-like option?
-
Why is
:projection :orthonot a reliable way to write an option? -
Are
:bpmand:BPMthe same keyword? -
Is
C#4a valid symbol? Is#C4?