librarydemos/xetal-pipes/stages/Pipes.xtl

Pipes: what every stage shares. A stage's input is one text, its lines each ending in a newline; l_ines numbers every character by the line it is on, so a stage chooses or reorders whole lines with a mask or a grade over those numbers, never a loop over lines.

source

end : Char

value (private) · line 9
end ← "<<xetal-end-of-input>>"
Used in: ʰr̲ead1

nl : Char

value (private) · line 10
nl ← f̲irst "\n"

z : Char

value (private) · line 13
z ← 1 t̲ake ⎕U̲CHAR 0

ʰe̲nded : Truthy a => Char -> a

function (private) · line 16
ʰe̲nded ← { t → (-1 t̲ake t) m̲atch z }

ʰr̲ead1 : Unit -> Char

function (private) · line 19
ʰr̲ead1 ← { @ → l ← ⎕R̲EAD @◆ l m̲atch end ? z◆ l c̲at nl }
Used in: ʰr̲eadn

ʰr̲eadn : Int -> Char

function (private) · line 24
ʰr̲eadn ← { n →
  n ≤ 1 ? ʰr̲ead1 @
  a ← ʰr̲eadn n d̲iv 2
  ʰe̲nded a ? a
  a c̲at ʰr̲eadn n − n d̲iv 2
}

ʰr̲eadall : Int -> Char

function (private) · line 32
ʰr̲eadall ← { n →
  a ← ʰr̲eadn n
  ʰe̲nded a ? -1 d̲rop a
  a c̲at ʰr̲eadall 2 × n
}

ˡr̲ead : Unit -> Char

function · line 39

Standard input, every line ending in a newline.

ˡr̲ead ← { @ → ʰr̲eadall 64 }

ˡo̲ut : Char -> Int

function · line 43

Write a text to standard output as it is (no newline added); how many characters.

ˡo̲ut ← { t → t ⎕N̲PUT "/dev/stdout" }

ˡl̲ines : (Num a, Truthy a) => Char -> a

function · line 47

Each character's line number, from 1 (a newline is on the line it ends).

ˡl̲ines ← { t → 1 + '+ s̲\ (t̲ally t) t̲ake 0 c̲at 1 × t = nl }
Used in: ˡk̲eep, ln

ˡc̲ount : (Num a, Truthy a) => Char -> a

function · line 50

How many lines.

ˡc̲ount ← { t → '+ r̲/ 1 × t = nl }

ˡk̲eep : Truthy a => a -> Char -> Char

function · line 53

The lines whose mask (one per line) is 1.

ˡk̲eep ← { mask t → ((ˡl̲ines t) s̲elect mask) r̲eplicate t }

ˡm̲atrix : Char -> Char

function · line 57

The lines as the rows of a matrix, each padded with character 0 to the longest (its newline left out).

ˡm̲atrix ← { t →
  ends ← w̲here t = nl
  starts ← (t̲ally ends) t̲ake 1 c̲at 1 + ends
  lens ← ends − starts
  w ← 1 m̲ax 'm̲ax r̲/ 0 c̲at lens
  inside ← lens '> t̲able o̲ffsets w
  at ← (starts '+ t̲able o̲ffsets w) × inside
  (at + (1 − inside) × 1 + t̲ally t) s̲elect t c̲at z
}
Used in: m