# FatScript Essentials Interpreted, concise, functional-style language. Syntax: explicit; designed for console apps/scripts. ## Comments Only line comments are supported: ``` # comment ``` ## Imports ``` console <- fat.console other <- myFile ``` ## Common Libraries - `_ <- fat.std` adds all native types and standard libraries to context: async, bridge, color, console, curses, enigma, failure, file, http, math, recode, sdk, smtp, socket, system, time - `console.log` adds newline, `console.print` does not, `console.input` prints prompt and reads input - `file.read(path)` reads a file, `file.write(path, val)` writes to a file ## Constants (`=`) and Variables (`~`) (camelCase) ``` name = 'Mary' ~ age = 25 ``` ## Lists (`[]`) ``` nums = [ 1, 2, 3 ] nums(0) # read-only nums[0] # mutable lists only ``` ## Scopes/Objects (`{}`) ``` user = { name='mary', age=30 } user.name # read/write user('name') # read-only user['name'] # read/write scope.valuesOf(T) # extract typed values ``` ## Types (PascalCase) Define classes/types: ``` Person = (name: Text, ~age: Number, birthday = <> self.age += 1) ``` ## Methods (`->`) and Procedures (`<>`) (camelCase) ``` greet = (name: Text) -> 'Hello, {name}' names = List <> users @ -> _.name ``` ## Control Flow ``` val ?? fallback # Nullish coalesce cond ? then : else # If-Else x => y # Match case val >> { case => result, _ => default} # Switch ``` ## Loops (`@`) ``` condition @ body # loop while condition 1..10 @ n -> handle(n) # n is number in range list @ item -> handle(item) # item is value .. handle(list(i)) # i is index, list(i) is value scope @ key -> use(key) # or handle(scope(key)) for value ``` ## Implicit Args (`_`) ``` double = -> _ * 2 ``` ## Error Handling ``` failure <- fat.failure SubtypeError = Error failure.trapWith(-> _ == SubtypeError ? handler : _) ``` ## Method Chaining ``` nums.reduce(reducer, {}).valuesOf(Type).sortBy('key').map(-> _.value) ``` ## Slicing and Ranges ``` 'hello'(1..) # 'ello' 'hello'(1..<4) # 'ell' nums(-2..) # last two elements ``` ## Text Manipulation ``` list.join('') text.split('') ``` ## Logical operators - `&` (AND) - `|` (OR) ``` x > 0 & y < 5 | z == 10 ``` ## Conventions - No binary ops, explicit methods only - PascalCase types, camelCase vars/methods - Mutable vars must be declared explicitly using `~` - Deep equality checks by default