Two inputs, words and the pipe

The first page used one operator at a time. This page puts several together. You will learn:

  • operators that take two inputs;
  • how Garo reads a line: right to left, with no precedence;
  • how glued syllables make a word that runs left to right;
  • how the pipe puts the data first.

Two inputs

Some flows pair two arrays. ㅜ is the inner flow: it pairs the two inputs' elements up. 둗 is reduce, inner, sum. It multiplies the pairs and adds the products, which is the dot product:

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

That is 1×4 + 2×5 + 3×6, or np.dot(a, b) in NumPy. Given two matrices, the same syllable is the matrix product, NumPy's A @ B:

둗 [[1, 2], [3, 4]] [[5, 6], [7, 8]]
⇒ [[19, 22], [43, 50]]Try it

The map family on the inner flow works pair by pair. 굳 adds corresponding elements, and 국 keeps the larger of each pair:

국 [1, 5, 2] [3, 3, 3]
⇒ [3, 5, 3]Try it

ㅗ is the outer flow: every pair, one from each input. 골 is map, outer, multiplicative, so it builds a times table:

골 [1, 2, 3] [1, 2, 3]
⇒ [[1, 2, 3], [2, 4, 6], [3, 6, 9]]Try it

A two-input operator takes its inputs in order, after any parameter. 즘 puts one array after another (combine, whole, cardinality):

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

Right to left, no precedence

Garo reads an expression from the right. Each operator, sign or syllable, applies to everything to its right. There is no rule that × goes before +.

2 × 3 + 4
⇒ 14Try it

That is 2 × (3 + 4), not (2 × 3) + 4. The same rule holds in APL and BQN. Use parentheses to say what you mean:

(2 × 3) + 4
⇒ 10Try it

The rule pays off with syllables. A syllable takes everything to its right as its data, so the sum of squares needs no parentheses:

닫 [1, 2, 3] × [1, 2, 3]
⇒ 14Try it

The × ran first, and 닫 summed its result. When you want a syllable to apply to less than the rest of the line, wrap it: (닫 xs) + 1.

Subtraction in a chain surprises people at first:

10 - 2 - 3
⇒ 11Try it

It is 10 − (2 − 3), so 11.

Words

Spaced syllables nest from the right, like everything else. In 님3 삭 xs, 삭 sorts descending first, and 님3 keeps the first three of the result: the top three.

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

Glue syllables together with no space and they make one word. A word runs left to right, the order you read it:

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

Read it as "sort descending, then keep three". That is SQL's ORDER BY x DESC LIMIT 3. Inside a word, a parameter must be glued to its syllable, as 님3 is.

The two spellings above happen to mean the same. They do not when the steps are swapped. Here is a word that sums each row and then takes the largest sum:

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

The rows sum to −1 and 1, and the larger is 1. Spaced, the same two syllables run the other way round: 닥 finds each row's largest value (1 and 4), and 닫 adds them.

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

One way to remember it: a space separates steps that run from the right, and glue joins steps that run from the left.

The pipe

A value, a dot, then a word: the dot feeds the value into the word. This is the pipe, and it lets you write the data first.

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

The data comes first, then sort ascending, then keep three. Dots can also separate the steps, which reads like a chain of method calls in Python or JavaScript:

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

With a named value, a pipe reads almost like a sentence:

prices := [12, 7, 30, 18, 5]
prices.삭님2.닫
⇒ 48Try it

That is the sum of the two highest prices.

What you have learned

  • ㅜ pairs two inputs up, and ㅗ takes every pair.
  • An expression runs right to left, and each operator takes everything to its right.
  • Glued syllables make a word, which runs left to right.
  • value.word pipes the value into the word.

Next, functions as operands shows how to hand an operator your own function.