tricu

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

text-summary.tri (1993B)


      1 !import prelude *
      2 !import io *
      3 !import conversions as C
      4 !import consumers_structural as S
      5 !import consumers_effect as E
      6 !import consumers_lexical_worker as X
      7 !export *
      8 -- One-file application adapter: generic SCP effects remain filesystem-free.
      9 -- Program trees are passed in; the adapter owns ReadText and presentation.
     10 
     11 -- The authored counter returns a compact tricu natural directly.
     12 -- Source, reference and lexical callers supply the matching successor value:
     13 -- an authored consumer for the oracle or an executable worker for lexical.
     14 counterState successor = pair 0 (pair t successor)
     15 render outcome = matchPair (tag value : lazyBool
     16   (_ : append "lines: " (C.showNumber value))
     17   (_ : append "read failed: " value) (equal? tag 1)) outcome
     18 readText path = readFile path
     19 -- The independent structural interpreter is an oracle, not a deployable
     20 -- specialization backend. The former runFull cannot lower computed matches.
     21 summary successor counter entry receiver path =
     22   onResult_ (E.run S.runConsumer
     23     [(pair "summaryEntry" entry)
     24      (pair "summaryReceiver" receiver)]
     25     [(pair "ReadText" readText)] "summaryEntry" path
     26     (S.makeConsumer (counterState successor) (snd counter)))
     27     (message : pure (pair 0 message))
     28     (outcome : pure outcome)
     29 -- Compiled pure counter and open-state effect receivers use one CPS ABI.
     30 -- The existing generic driver still handles names and real ReadText; no file
     31 -- traversal or receiver-specific dispatch is added to the compiler or driver.
     32 summaryLexical counterWorker entryWorker receiverWorker path =
     33   onResult_ (E.run X.lEffectStep
     34     [(pair "summaryEntry" (S.makeConsumer t entryWorker))
     35      (pair "summaryReceiver" (S.makeConsumer t receiverWorker))]
     36     [(pair "ReadText" readText)] "summaryEntry" path counterWorker)
     37     (message : pure (pair 0 message))
     38     (outcome : pure outcome)
     39 printSummary successor counter entry receiver path = bind (summary successor counter entry receiver path) (outcome : putStrLn (render outcome))