Syntax

This page covers how Garo is written: what each piece of a line is, and how a line is read. It describes the expression layer, which is all of Garo that runs today.

Programs

A program is a few lines:

  1. optional enum declarations, one per line;
  2. optional bindings, name := expr, one per line;
  3. one expression, whose value is the result.
enum Size = `s | `m | `l
xs := [3, 1, 2]
ys := xs × 10
닫 ys
⇒ 60Try it

A binding's name starts with a lowercase letter, and may hold letters, digits and _. A name can be used on any later line. Avoid x, y and z, which blocks use for their arguments.

There are no comments yet.

Literals

KindExamplesNotes
Int42, -7, 0whole numbers of any size
Float3.5, -0.25, ∞, -∞needs a digit on both sides of the point
Booltrue, false
Sym`east, `q1a backquote, then letters, digits or _
Text"hello"no escapes yet
absent`nonea missing value

A - glued to a number, where a value is expected, makes a negative number. After a value, - is subtraction, glued or not:

5 -1
⇒ 4Try it

There is no exponent notation such as 1e3.

Arrays

Arrays are written in square brackets, with commas. Every element has one type, and every inner array has the same shape: arrays are rectangular.

[[1, 2, 3], [4, 5, 6]]
⇒ [[1, 2, 3], [4, 5, 6]]Try it

[] is an empty array. Ints and Floats may mix, and the array is then Floats. Two values side by side with no comma are an error: Garo has no other way to write an array.

[1, 2] [3, 4]
⇒ !syntax: two values side by side: Garo has no stranding, so write arrays as [a, b]Try it

Indexing

a[i] picks along the first axis, counting from 0. A list of positions picks several, in that order. A position past the end gives `none.

[10, 20, 30][[2, 0]]
⇒ [30, 10]Try it

a[p] with a partition p groups the values. See groups.

Tables and records

Table {name: [..], other: [..]}
Record {name: value, other: value}

A table's columns are arrays of one length. A record's fields are values. A name appears once. t.name takes a column or a field:

(Record {a: 1, b: [2, 3]}).b
⇒ [2, 3]Try it

Parentheses

Parentheses group. They never make an array.

  • Parentheses around values, or around a mix of values and functions, are an expression: (닫 [1, 2]) is 3.
  • Parentheses around functions only are a function: a train (see combinators).

Syllables and parameters

A syllable is an operator. The general shape is:

[function] SYLLABLE [parameter] data [data]
  • A function operand goes glued on the left, and only for an open syllable (a bare form or a lift form): +다, {x × x}기.
  • A parameter comes right after the syllable, spaced or glued: 긱 0, 님3.
  • Then the data: one input, or two for a syllable with two inputs (둗 a b).

A parameter that is not a plain number, glued or spaced, is wrapped in parentheses or written as an array: 님 (1 + 1), 망[2, 2].

Right to left

An expression is read from the right, with no precedence. Each function (a sign, a syllable, a block) applies to everything on its right.

2 × 3 + 4
⇒ 14Try it

That is 2 × (3 + 4). To apply something to less than the rest of the line, use parentheses: (닫 a) + 1.

A sign between two values is a two-input function: a - b. A function with only a value on its right gets one input: 깃 xs, or ×~ 4.

Words

Glued syllables make a word, and a word runs left to right. Spaced syllables nest from the right.

닫닥 [[1, -2], [-3, 4]]
⇒ 1Try it
닫 닥 [[1, -2], [-3, 4]]
⇒ 5Try it

The word 닫닥 sums each row, then takes the largest. The spaced 닫 닥 takes each row's largest, then sums.

Inside a word, a parameter must be glued to its syllable. A spaced parameter inside a word is an error, because it could belong to either side:

깃님 3 [1, 2, 3, 4]
⇒ !syntax: 님 is inside a word, so its parameter is glued to it: 님p, or put a space before 님 to apply it instead (D112)Try it

An open syllable glued after a word takes the whole word as its function: 긎닫가 is "(positions, then sum) for each row". A math sign glued before an open syllable is its whole operand, so it starts a new step: 긱0+다 is "clamp at 0, then reduce by +".

The pipe

A value, then a dot, then a word is a pipe: the value goes into the word.

[3, 1, 4, 1, 5].산님3
⇒ [1, 1, 3]Try it

Dots may also separate the steps: xs.산.님3. After a value, a dot followed by a name is a field: orders.amount.

Blocks

A block is a function in braces.

  • {x × x} has one argument, x.
  • {x - y} has two, x and y. Called between two values, 3 {x - y} 1, x is the left one.
  • {price ⇒ price × 2} names its argument. {a, b ⇒ a - b} names two. At most two.
  • The spec also describes a third argument, z. It is not available yet.

A block nested in another has its own x. Name the outer argument with ⇒ when both are needed.

A block with keys on the left of ⇒ is a keyed-arm literal, Garo's one way to branch:

{ `true ⇒ 0, `false ⇒ 5 } (3 > 4)
⇒ 5Try it

The values and types page covers its rules.

Combinators

FormMeaningExample
F.GF, then G(긱 0).닫
F~ xF with x on both sides×~ 4 is 16
x F~ yF with its inputs swapped3 -~ 10 is 7
x F @ G yG on each input, then F[1, 2] - @ 닫 [3] is 0
(F G H)fork: (F x) G (H x)(닫 ÷ 담) is the mean
(F G)atop: F (G x)(깃 닫) is the negated sum
F << GG, then F ("F of G")({x × 10} << {x + 1}) 3 is 40
?FTry: `ok result or `err kind(?{1 ÷ x}) 0

A train longer than three groups from the right in threes.

3 (+ @ ×~) 4
⇒ 25Try it

That is 3² + 4².

A syllable with its parameter, in parentheses or after . or @, is a function of its data: (깊 0), (+고). A function in parentheses can sit between two values, like a sign:

[1, 2] (+고) [10, 20]
⇒ [[11, 21], [12, 22]]Try it

Names that start with a capital

A capitalized name is a function. The ones that exist today are:

  • Date [y, m, d] and Days n, for dates;
  • Table and Record, for literals;
  • the name of an enum you declared, which turns a position into a label (Size 0 is `s).

Your own named functions need the sentence layer, which is not available yet.

Spaces

  • Spaces between tokens are free, except where gluing means something.
  • Gluing a function to an open syllable forms it: +다. Spaced, + 다 is not the same.
  • Gluing syllables makes a word.
  • Gluing a parameter to its syllable is allowed alone, and required inside a word.
  • Newlines end a line. A program is one item per line.