The Oxford Comma
Let's go over Sparkle's use of the Oxford comma.
In English
The Oxford comma (, and) in English is used to disambiguate between elements in a
sequence.
In Sparkle
In Sparkle, it plays a crucial role in disambiguating between nested sequences. Missing it is considered a syntax error and will prevent the script from running, as the parser cannot reliably determine which element is the last element in the sequence.
It is used for list elements, object properties, function arguments, and import statements.
let numbers be list with 1, list with 2, 3, and 4, 5, and 6The Oxford comma acts as an indicator that the next element is the last element in the sequence.
Single Element
For the same reasons, if there's only one element in the sequence, just is required
to indicate that there is only one element.
let numbers be list with 1, 2, list with just 3, 4, and 5In Practice
In practice, it means you need to be mindful of using just and , and when
defining lists, objects, functions, and imports. Below are a couple examples.
Single Item
let names be list with just "alice"
let person be object with just name as "alice"
let say_hello be function with just name do
print "hello {name}"
import just swap from "./swap.sparkle"Multiple Items
let names be list with "alice", "bob", and "charlie"
let person be object with name as "alice", and age as 30
let say_hello be function with name, and age do
print "hello {name}, you are {age} years old"
import swap, and magenta from "./swap.sparkle"Nested Items
let person be object with
name as "alice",
friends as list with "bob", "charlie", and "dave", and
greet as method as
print "my name is {own's name} and my friends are {own's friends}"Conclusion
Use the Oxford comma in Sparkle and in your everyday life, starting today!