Syntax

Essential aspects

# Imports (<-)
console <- fat.console

# Constants (cannot be changed)
name = 'Mary'
age = 25

# Variables (can be changed, marked with ~)
~ email = 'my@email.com'
~ isOnline = true

# Collections (lists and objects)
list = [ 1, 2, 3 ]
scope = { key1 = 'value1', key2 = 'value2' }

# Types (names start with uppercase)
Person = (name: Text, age: Number)
mary = Person('Mary', 25)

# Access elements in collections
list(0)        # Outputs 1, read-only
list[0]        # Outputs 1, read/write, in case list can be changed
scope.key1     # Outputs 'value1' (dot access)
scope('key1')  # Outputs 'value1' (call access)

# Methods (functions ->)
greeting = (name: Text): Text -> 'Hello, {name}'
console.log(greeting('World'))

# Nullish coalescing (??)
maybeValue ?? fallback    # use fallback if maybeValue is null/error

# If-Else (_ ? _ : _)
condition ? then : else   # if condition is true, then do "then", otherwise "else"

# Match multiple conditions (=>)
condition1 => result1
condition2 => result2
conditionN => resultN
_          => default     # catch-all case

# Switch based on a value (>>)
value >> {
  match1 => result1
  match2 => result2
  matchN => resultN
  _      => default       # catch-all case
}

# Tap: use methods in a chain (<<)
expression << tapMethod   # uses tapMethod only for it's effects

# Loops (@)
condition @ loopBody              # loop while the condition is true
1..10 @ n -> rangeMapper(n)       # iterate over the range 1 to 10
list @ item -> listMapper(item)   # iterate over list items
scope @ key -> scopeMapper(key)   # iterate over scope keys

Deep dive

In the following pages, you will find information on the central aspects of writing FatScript code, using both the basic language features as well as the advanced type system and standard libraries features.

  • Formatting: how to format FatScript code properly

  • Imports: how to import libraries into your code

  • Entries: understanding the concept of entries and scopes

  • Types: a guide to FatScript type system

  • Flow control: controlling the program execution with conditionals

  • Loops: making use of ranges, map-over and while loops

results matching ""

    No results matching ""