librarylib/Text.xtl

Text: printing lines, shared by the games.

source

ˡl̲ines : Num b => Box a -> b

function · line 10

Print each string of a strand on its own line; how many were printed.

      ᵗ⁼u̲se< "Text"
      ᵗl̲ines "one" "two"
one
two
2
ˡl̲ines ← { v →
  0 = t̲ally v ? 0
  said ← p̲rint! d̲isclose f̲irst v
  1 + ˡl̲ines 1 d̲rop v
}

ˡh̲olds : Truthy a => Int -> Int -> a

function · line 23

Which rows of a text table hold in state s: a row's condition is a state item (0: always) and the value it must have, the second and third rows of kfv (the first row, the keys, is for the caller to match: w_here (keys m_ember? k) & kfv t:h_olds s).

      ᵗ⁼u̲se< "Text"
      (3 4 r̲eshape 1 1 2 2 0 2 0 2 0 1 0 0) ᵗh̲olds 0 1
1 1 1 0
ˡh̲olds ← { kfv s →
  f ← 2 s̲elect kfv
  (f = 0) ∨ (3 s̲elect kfv) = (1 + f) s̲elect -1 c̲at s
}
Used in: ˡl̲ines

ˡj̲oin : Box Char -> Char

function · line 34

The boxed texts b joined into one text, in pairs, level by level: each level copies the text once, so n texts cost n log n, not the n squared of a reduce with c_at (X_eTaL has no built-in join yet: an ask).

      ᵗ⁼u̲se< "Text"
      ᵗj̲oin "ab" "c" "def"
abcdef
ˡj̲oin ← { b →
  0 = t̲ally b ? ""
  1 = t̲ally b ? d̲isclose f̲irst b
  e ← b c̲at (2 m̲od t̲ally b) r̲eshape e̲nclose ""
  odd ← (2 × r̲ange (t̲ally e) d̲iv 2) − 1
  ˡj̲oin (odd s̲elect e) '{ x y → e̲nclose (d̲isclose x) c̲at d̲isclose y } e̲ach (odd + 1) s̲elect e
}