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.
ʰr̲eadn : Int -> Char
ʰ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
ʰr̲eadall ← { n → a ← ʰr̲eadn n ʰe̲nded a ? -1 d̲rop a a c̲at ʰr̲eadall 2 × n }
ˡo̲ut : Char -> Int
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
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 }
ˡc̲ount : (Num a, Truthy a) => Char -> a
How many lines.
ˡc̲ount ← { t → '+ r̲/ 1 × t = nl }
Used in: demos/xetal-pipes/xetal-pipes.xtl:55
ˡk̲eep : Truthy a => a -> Char -> Char
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
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