programdemos/xetal-pipes/xetal-pipes.xtl
Unix pipes in X_eTaL: the arrays inside the stages (stages/*.xtl), shown on sample.txt. A stage reads standard input as one text; here the same text comes from the file. Every character is numbered by its line, so choosing lines is a mask and reordering them a grade: no loop over lines anywhere. Run it with "xetal run demos/xetal-pipes/xetal-pipes.xtl"; it prints the first line's character-to-line numbers, the counts xetalwc would give, where "lazy" starts and which lines it is on (grep), the padded lines' shape and which lines uniq keeps, and each line's rank and the text sorted by it. No live page: command line only (see the stages, xetalcat and friends, in the demo's README).
ln : Int
-- every character's line: a running sum of newlines. ln: as stages/Pipes.xtl's l:l_ines computes it.
ln ← ᵖl̲ines t
grep: the text's k rotations against the needle
needle : Char
needle, k, tt: the needle to find, its length, and the text repeated k times (so a rotation of it lines up with every start). starts: 1 wherever the needle starts: the k rotations' characters compared with the needle's, then reduced by & (and-reduce). hits: the lines those characters are on.
needle ← "lazy"
starts : Bool
starts ← (t̲ally t) t̲ake '∧ r̲/₁ ((o̲ffsets k) o̲- tt) = needle 'l̲eft t̲able tt
uniq: a line stays when its padded row differs from the row above
m : Char
m: the lines as a padded character matrix (Pipes.xtl's l:m_atrix). differs: 1 where a row differs from the one above it (the matrix rotated down one row).
m ← ᵖm̲atrix t
differs : Int
differs ← 1 c̲at 1 d̲rop '∨ r̲/₂ m ≠ -1 o̲-₁ m