Changeset 40425 in project


Ignore:
Timestamp:
09/07/21 01:56:51 (2 weeks ago)
Author:
Zipheir
Message:

Document generator/accumulator procedures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/srfi-135

    r40408 r40425  
    1010
    1111This egg provides the UTF-8 version of the SRFI 135 sample
    12 implementation.
     12implementation; all procedures provided are fully Unicode-aware.
    1313
    1414[[toc:]]
     
    896896</enscript>
    897897
     898=== Generators and accumulators
     899
     900The following procedures provide [[srfi-158]] generators and
     901accumulators for immutable texts. They are extensions to SRFI 135.
     902
     903See [[https://srfi.schemers.org/srfi-158/srfi-158.html|SRFI 158]] for
     904more information on generators and accumulators.
     905
     906<procedure>(textual->generator textual [[start] end]) → procedure</procedure>
     907
     908Returns a generator that produces the elements (codepoints) of
     909''textual'' in order. If the optional ''start'' or ''end''
     910arguments are provided, then only the elements of
     911{{(subtext textual start end}} will be produced.
     912
     913Example:
     914
     915<enscript highlight="scheme">
     916(let ((gen (textual->generator (text #\a #\b #\c #\d) 2)))
     917  (generator->list gen))
     918  ⇒ (#\c #\d)
     919</enscript>
     920
     921<procedure>(generator->text gen [max]) → text</procedure>
     922
     923Returns a text of the characters produced by {{gen}}, in order. If
     924{{max}} is provided and is an exact natural number, then at most
     925{{max}} values will be read from {{gen}}.  Otherwise, reading
     926continues until {{gen}} returns EOF.
     927
     928Example:
     929
     930<enscript highlight="scheme">
     931(let ((gen (list->generator '(#\a #\b #\c #\d))))
     932  (generator->text gen))
     933  ⇒ «abcd»
     934</enscript>
     935
     936<procedure>(text-accumulator) → procedure</procedure>
     937
     938Returns an accumulator that, when invoked on a character, appends
     939that character to an (initially empty) internal text and returns
     940an unspecified value. Invoking the accumulator on an eof-object
     941instead returns the accumulated text.
     942
     943Example:
     944
     945<enscript highlight="scheme">
     946(let ((acc (text-accumulator)))
     947  (acc #\a)
     948  (acc #\b)
     949  (acc #\c)
     950  (acc #!eof))
     951  ⇒ «abc»
     952</enscript>
     953
    898954== About This Egg
    899955
Note: See TracChangeset for help on using the changeset viewer.