tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

text-summary-lambda.tri (1584B)


      1 !import prelude *
      2 !import io *
      3 !import consumers_text_summary as Summary
      4 !export *
      5 -- Comparable one-file lambda route using the same host read and renderer.
      6 countBytes_ self bytes count pending = lazyList (_ : lazyBool (_ : count) (_ : succ count) (equal? pending t)) (byte rest : lazyBool (_ : self rest (succ count) t) (_ : self rest count (t t)) (equal? byte 10)) bytes
      7 countBytes bytes = y countBytes_ bytes 0 t
      8 -- Historical lambda-only unary comparator; SCP now returns compact numbers.
      9 countBytesUnary_ self bytes count pending = (lazyList
     10   (_ : lazyBool (_ : count) (_ : t count) (equal? pending t))
     11   (byte rest : lazyBool (_ : self rest (t count) t)
     12     (_ : self rest count (t t)) (equal? byte 10)) bytes)
     13 countBytesUnary bytes = y countBytesUnary_ bytes t t
     14 lambdaSummaryUnary path = (onResult_ (readFile path)
     15   (problem : pure (pair 0 problem))
     16   (bytes : pure (pair 1 (countBytesUnary bytes))))
     17 unaryNumber_ self unary acc = (triage acc
     18   (child : self child (succ acc)) (_ _ : acc) unary)
     19 unaryNumber unary = y unaryNumber_ unary 0
     20 renderUnary outcome = matchPair (tag value : lazyBool
     21   (_ : append "lines: " (showNumber (unaryNumber value)))
     22   (_ : append "read failed: " value) (equal? tag 1)) outcome
     23 lambdaSummary path = onResult_ (readFile path) (problem : pure (pair 0 problem)) (bytes : pure (pair 1 (countBytes bytes)))
     24 render outcome = matchPair (tag value : lazyBool
     25   (_ : append "lines: " (showNumber value))
     26   (_ : append "read failed: " value) (equal? tag 1)) outcome
     27 printLambda path = bind (lambdaSummary path) (outcome : putStrLn (render outcome))