Sparkle Reference Sheet

Hello World

print "hello world"

This is actually a macro!

Comments

# this is a comment

Primitives

let some_blank be blank
let some_boolean be true
let some_number be 42
let some_string be "hello world"

update some_string to "the answer is {some_number}"

let long_message be quote
  | this is a very long
  | string with many lines
  | and even interpolation:
  | {some_boolean}

Lists and Objects

let fruits be list with "apple", "banana", and "orange"
let first_fruit be fruits at 0

let person be object with name as "alice", and age as 22
let alice be person's name

Functions

let greet be function with just name as
  print "hello {name}!"

call greet with just "Alice"

let add be function with a, and b as a plus b
print call add with 1, and 2

Conditionals

let x be 5
if x is greater than 10 do
  print "x is big"
otherwise if x is less than 10 do
  print "x is small"
otherwise
  print "x is just right"

Loops

while x is greater than 0 do
  print "remaining: {x}"
  update x to x minus 1

for each item in some_list do
  print "i like {item}"

for each key in some_object do
  print "alice's {key} is {some_object at key}"

for each letter in "hello world" do
  print letter

Classes and Methods

let Person be class with name, and age defined with
  name as name,
  age as age, and

  greet as method as
    print "hello my name is {own's name}"

let alice be new Person with "alice", and 25

call alice's greet
Note: classes in Sparkle do not support inheritance.

Modules

# relative paths with "./" or "../"
import just lucky_number from "./numbers.sparkle"
print "the lucky number is {lucky_number}!"

Important Notes

  • Sparkle uses the Oxford comma for lists, objects, and functions.
  • Sparkle does not have a form of implicit type coercion.
  • Values are deep copied by default, read References.
  • Indentation matters.