Changeset 12660 in project


Ignore:
Timestamp:
11/30/08 18:56:37 (11 years ago)
Author:
azul
Message:

Lots of tweaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/stream-ext

    r12654 r12660  
    4646=== stream-xcons
    4747
    48 <procedure name="stream-xcons" args="a b" returns="stream">
     48<procedure>(stream-xcons stream object)</procedure>
     49
     50Creates a stream prepending {{object}} to {{stream}}.
     51The name stands for "eXchanged CONS."
     52
    4953Of utility only as a value to be conveniently passed to higher-order procedures.
    5054
    51 <examples>
    52 <expr>(stream-xcons (stream 'b 'c) 'a)</expr>
    53 <result>#<stream (a b c)></result>
     55<examples testgroup="stream-xcons" filename="stream-ext">
     56<example>
     57<expr>(stream-xcons (stream 2 3) 1)</expr>
     58<result>(stream 1 2 3)</result>
     59<resultcmp>(cut stream= equal? <...>)</resultcmp>
     60</example>
     61<example>
    5462<expr>(stream-xcons (stream 2 3 4) 1)</expr>
    55 <result>#<stream 1 2 3 4></result>
     63<result>(stream 1 2 3 4)</result>
     64<resultcmp>(cut stream= = <...>)</resultcmp>
     65</example>
    5666</examples>
    5767
    58 The name stands for "eXchanged CONS."
    59 
    60 <enscript highlight=scheme filename='stream-ext'>
    61 (define (stream-xcons a b) (stream-cons b a))
    62 </enscript>
    63 </procedure>
     68<enscript highlight=scheme filename='stream-ext'>
     69(define (stream-xcons stream object) (stream-cons object stream))
     70</enscript>
    6471
    6572=== stream-cons*
    6673
    67 <procedure name="stream-cons*" returns="stream" args="a b">
     74<procedure>(stream-cons* [elt1 ...] tail)</procedure>
    6875
    6976Like {{stream}}, but the last argument
     
    7279<enscript highlight=scheme>(stream-cons elt1 (stream-cons elt2 (stream-cons ... eltn)))</enscript>
    7380
    74 <examples>
     81<examples testgroup="stream-cons*" filename="stream-ext">
     82<example>
    7583<expr>(stream-cons* 1 2 3 (stream 4))</expr>
    76 <result>#<stream (1 2 3 4)></result>
     84<result>(stream 1 2 3 4)</result>
     85<resultcmp>(cut stream= = <...>)</resultcmp>
     86</example>
     87<example>
    7788<expr>(stream-cons* (stream 4))</expr>
    78 <result>#<stream (4)></result>
     89<result>(stream 4)</result>
     90<resultcmp>(cut stream= = <...>)</resultcmp>
     91</example>
    7992</examples>
    8093
     
    90103=== make-stream
    91104
    92  [procedure] (make-stream n [fill])
     105<procedure>(make-stream n [fill])</procedure>
    93106
    94107Returns an {{n}}-element stream, whose elements
     
    97110the elements of the stream may be arbitrary values.
    98111
    99 <enscript highlight=scheme>(make-stream 4 'c)
    100 => <stream (c c c c)></enscript>
     112<examples testgroup="make-stream" filename="stream-ext">
     113<example>
     114<expr>(make-stream 4 0)</expr>
     115<result>(stream 0 0 0 0)</result>
     116<resultcmp>(cut stream= = <...>)</resultcmp>
     117</example>
     118</examples>
    101119
    102120<enscript highlight=scheme filename='stream-ext'>
     
    108126=== stream-tabulate
    109127
    110  [procedure] (stream-tabulate n init-proc)
     128<procedure>(stream-tabulate n init-proc)</procedure>
    111129
    112130Returns an {{n}}-element list.
     
    114132is produced by {{(init-proc i)}}.
    115133
    116 <enscript highlight=scheme>(stream-tabulate 4 identity)
    117 => #<stream (0 1 2 3)></enscript>
     134<examples testgroup="make-stream" filename="stream-ext">
     135<example>
     136<expr>(stream-tabulate 4 (lambda (x) (* x x)))</expr>
     137<result>(stream 0 4 9 16)</result>
     138<resultcmp>(cut stream= = <...>)</resultcmp>
     139</example>
     140</examples>
    118141
    119142<enscript highlight=scheme filename='stream-ext'>
     
    131154=== stream-iota
    132155
    133  [procedure] (stream-iota a b)
     156<procedure>(stream-iota a b)</procedure>
    134157
    135158Returns a list containing the elements:
     
    141164This procedure takes its name from the APL primitive.
    142165
    143 <enscript highlight=scheme>(stream-iota 5)
    144 => #<stream (0 1 2 3 4)>
    145 (stream-iota 5 0 -0.1)
    146 => #<stream (0 -0.1 -0.2 -0.3 -0.4)></enscript>
     166<examples testgroup="stream-iota" filename="stream-ext">
     167<example>
     168<expr>(stream-iota 5)</expr>
     169<result>(stream 0 1 2 3 4)</result>
     170<resultcmp>(cut stream= = <...>)</resultcmp>
     171</example>
     172<example>
     173<expr>(stream-iota 5 0 -0.1)</expr>
     174<result>(stream 0 -0.1 -0.2 -0.3 -0.4)</result>
     175<resultcmp>(cut stream= = <...>)</resultcmp>
     176</example>
     177</examples>
    147178
    148179<enscript highlight=scheme filename='stream-ext'>
     
    157188</enscript>
    158189
    159 === stream-format
    160 
    161  [procedure] (stream-format fmt ...)
    162 
    163 Does the same as {{(format #f fmt ...)}},
    164 but returns the result as a stream of characters rather than a string.
    165 
    166 <enscript highlight=scheme filename='stream-ext'>
    167 (define (stream-format fmt . rest)
    168   (string->stream (apply format #f fmt rest)))
    169 </enscript>
    170 
    171 === stream-lines
    172 
    173  [procedure] (stream-lines str)
    174 
    175 Returns a stream with the lines found in the stream of
    176 characters {{str}}.  Each line is itself returned
    177 as a stream of characters.  It is an error if {{str}} contains
    178 elements that are not characters.
    179 
    180 <enscript highlight=scheme>(stream-lines (stream #\h #\e #\y #\newline #\y #\o #\u))
    181 => #<stream (#<stream (#\h #\e #\y)> #<stream (#\y #\o #\u)>)></enscript>
    182 
    183 <enscript highlight=scheme filename='stream-ext'>
    184 (define stream-lines (cut stream-split <> (cut equal? <> #\newline)))
    185 </enscript>
    186 
    187 === stream-unlines
    188 
    189 TODO: Document
    190 
    191 <enscript highlight=scheme filename='stream-ext'>
    192 (define (stream-unlines lines)
    193   (stream-concatenate (stream-intersperse lines (stream #\newline))))
    194 </enscript>
    195 
    196190=== make-infinite-stream
    197191
     
    209203=== stream->list
    210204
    211  [procedure] (stream->list str)
     205<procedure>(stream->list str)</procedure>
    212206
    213207Returns a list with the elements in stream {{str}}.
     
    223217=== list->stream
    224218
    225  [procedure] (list->stream list)
     219<procedure>(list->stream list)</procedure>
    226220
    227221Returns a stream with the elements in list {{list}}.
     
    239233=== stream->string
    240234
    241  [procedure] (stream->string str)
     235<procedure>(stream->string str)</procedure>
    242236
    243237Returns a string with its characters read from
     
    254248=== string->stream
    255249
    256  [procedure] (string->stream str [tail])
     250<procedure>(string->stream str [tail])</procedure>
    257251
    258252Returns a finite stream with the characters
     
    274268=== number->stream
    275269
    276  [procedure] (number->stream str)
     270<procedure>(number->stream str)</procedure>
    277271
    278272...
     
    284278=== stream->number
    285279
    286  [procedure] (stream->number str)
     280<procedure>(stream->number str)</procedure>
    287281
    288282...
     
    294288=== stream->vector
    295289
    296  [procedure] (stream->vector str)
     290<procedure>(stream->vector str)</procedure>
    297291
    298292...
     
    304298=== vector->stream
    305299
    306  [procedure] (vector->stream str)
     300<procedure>(vector->stream str)</procedure>
    307301
    308302...
     
    314308=== stream->symbol
    315309
    316  [procedure] (stream->symbol str)
     310<procedure>(stream->symbol str)</procedure>
    317311
    318312...
     
    324318=== symbol->stream
    325319
    326  [procedure] (symbol->stream str)
     320<procedure>(symbol->stream str)</procedure>
    327321
    328322...
     
    334328=== port->stream
    335329
    336  [procedure] (port->stream [in [reader [close-at-eof]]])
     330<procedure>(port->stream [in [reader [close-at-eof]]])</procedure>
    337331
    338332Returns a stream with the contents of the input port {{in}},
     
    368362=== iterator->stream
    369363
    370  [procedure] (iterator->stream proc)
     364<procedure>(iterator->stream proc)</procedure>
    371365
    372366Turns an iterator into a stream.  {{proc}} should be
     
    412406=== with-output-to-stream
    413407
    414  [procedure] (with-output-to-stream proc)
     408<procedure>(with-output-to-stream proc)</procedure>
    415409
    416410Returns a stream of characters, which is built by calling
     
    450444=== with-input-from-stream
    451445
    452  [procedure] (with-input-from-stream stream proc)
     446<procedure>(with-input-from-stream stream proc)</procedure>
    453447
    454448<enscript highlight=scheme filename='stream-ext'>
     
    473467=== write-stream
    474468
    475  [procedure] (write-stream stream [port [writer]])
     469<procedure>(write-stream stream [port [writer]])</procedure>
    476470
    477471Write all the elements in the stream {{stream}} to the output port {{port}},
     
    498492=== stream=
    499493
    500  [procedure] (stream= elt= str1 ...)
     494<procedure>(stream= elt= str1 ...)</procedure>
    501495
    502496Determines stream equality, given an element-equality procedure.
     
    549543=== stream-prefix=
    550544
    551  [procedure] (stream-prefix= str prefix [=])
     545<procedure>(stream-prefix= str prefix [=])</procedure>
    552546
    553547Evaluates whether the elements at the beginning of stream
     
    598592=== stream-caar ... stream-cddddr
    599593
    600  [procedure] (stream-caar pair)
    601  [procedure] (stream-cadr pair)
    602  :
    603  [procedure] (stream-cdddar pair)
    604  [procedure] (stream-cddddr pair)
     594<procedure>(stream-caar stream)</procedure>
     595<procedure>(stream-cadr stream)</procedure>
     596<procedure>(stream-cdar stream)</procedure>
     597<procedure>(stream-cddr stream)</procedure>
     598
     599<procedure>(stream-caaar stream)</procedure>
     600<procedure>(stream-caadr stream)</procedure>
     601<procedure>(stream-cadar stream)</procedure>
     602<procedure>(stream-caddr stream)</procedure>
     603<procedure>(stream-cdaar stream)</procedure>
     604<procedure>(stream-cdadr stream)</procedure>
     605<procedure>(stream-cddar stream)</procedure>
     606<procedure>(stream-cdddr stream)</procedure>
     607
     608<procedure>(stream-caaaar stream)</procedure>
     609<procedure>(stream-caaadr stream)</procedure>
     610<procedure>(stream-caadar stream)</procedure>
     611<procedure>(stream-caaddr stream)</procedure>
     612<procedure>(stream-cadaar stream)</procedure>
     613<procedure>(stream-cadadr stream)</procedure>
     614<procedure>(stream-caddar stream)</procedure>
     615<procedure>(stream-cadddr stream)</procedure>
     616<procedure>(stream-cdaaar stream)</procedure>
     617<procedure>(stream-cdaadr stream)</procedure>
     618<procedure>(stream-cdadar stream)</procedure>
     619<procedure>(stream-cdaddr stream)</procedure>
     620<procedure>(stream-cddaar stream)</procedure>
     621<procedure>(stream-cddadr stream)</procedure>
     622<procedure>(stream-cdddar stream)</procedure>
     623<procedure>(stream-cddddr stream)</procedure>
    605624
    606625These procedures are compositions of
     
    648667=== stream-ref
    649668
    650  [procedure] (stream-ref str pos)
     669<procedure>(stream-ref str pos)</procedure>
    651670
    652671Returns the element in the stream {{str}} at the
     
    667686=== stream-first ... stream-tenth
    668687
    669  [procedure] (stream-first str)
    670  [procedure] (stream-second str)
    671  :
    672  [procedure] (stream-ninth str)
    673  [procedure] (stream-tenth str)
     688<procedure>(stream-first str)</procedure>
     689<procedure>(stream-second str)</procedure>
     690<procedure>(stream-third str)</procedure>
     691<procedure>(stream-fourth str)</procedure>
     692<procedure>(stream-fifth str)</procedure>
     693<procedure>(stream-sixth str)</procedure>
     694<procedure>(stream-seventh str)</procedure>
     695<procedure>(stream-sixth str)</procedure>
     696<procedure>(stream-eighth str)</procedure>
     697<procedure>(stream-tenth str)</procedure>
    674698
    675699Synonyms for {{(stream-car str)}},
     
    680704
    681705<enscript highlight=scheme filename='stream-ext'>
    682 (define stream-first  stream-car)
    683 (define stream-second stream-cadr)
    684 (define stream-third  stream-caddr)
    685 (define stream-fourth stream-cadddr)
    686 (define (stream-fifth   x) (stream-car    (stream-cddddr x)))
    687 (define (stream-sixth   x) (stream-cadr   (stream-cddddr x)))
    688 (define (stream-seventh x) (stream-caddr  (stream-cddddr x)))
    689 (define (stream-eighth  x) (stream-cadddr (stream-cddddr x)))
    690 (define (stream-ninth   x) (stream-car  (stream-cddddr (stream-cddddr x))))
    691 (define (stream-tenth   x) (stream-cadr (stream-cddddr (stream-cddddr x))))
     706(define stream-first   stream-car)
     707(define stream-second  stream-cadr)
     708(define stream-third   stream-caddr)
     709(define stream-fourth  stream-cadddr)
     710(define stream-fifth   (compose stream-car    stream-cddddr))
     711(define stream-sixth   (compose stream-cadr   stream-cddddr))
     712(define stream-seventh (compose stream-caddr  stream-cddddr))
     713(define stream-eighth  (compose stream-cadddr stream-cddddr))
     714(define stream-ninth   (compose stream-car    stream-cddddr stream-cddddr))
     715(define stream-tenth   (compose stream-cadr   stream-cddddr stream-cddddr))
    692716</enscript>
    693717
    694718=== stream-take, stream-take-safe
    695719
    696  [procedure] (stream-take str count)
    697  [procedure] (stream-take-safe str count)
     720<procedure>(stream-take str count)</procedure>
     721<procedure>(stream-take-safe str count)</procedure>
    698722
    699723Returns a stream with the first {{count}} elements
     
    723747=== stream-drop, stream-drop-safe
    724748
    725  [procedure] (stream-drop str count)
    726  [procedure] (stream-drop-safe str count)
     749<procedure>(stream-drop str count)</procedure>
     750<procedure>(stream-drop-safe str count)</procedure>
    727751
    728752Returns the sub-stream of {{str}} obtained by omitting
     
    753777=== stream-intersperse
    754778
    755  [procedure] (stream-intersperse stream element)
     779<procedure>(stream-intersperse stream element)</procedure>
    756780
    757781Returns a new stream with the elements in the stream {{stream}}
     
    778802=== stream-split
    779803
    780  [procedure] (stream-split str pred)
     804<procedure>(stream-split str pred)</procedure>
    781805
    782806Splits the stream {{str}} into multiple streams, removing
     
    807831=== stream-last
    808832
    809  [procedure] (stream-last str)
     833<procedure>(stream-last str)</procedure>
    810834
    811835Returns the last element of the non-empty finite stream {{str}}.
     
    829853=== stream-last-n
    830854
    831 [procedure] (stream-last-n stream count)
     855<rocedure>(stream-last-n stream count)</procedure>
    832856
    833857Returns a stream with the last {{count}}
     
    867891=== stream-butlast
    868892
    869  [procedure] (stream-butlast stream)
     893<procedure>(stream-butlast stream)</procedure>
    870894
    871895Returns a stream with all the elements in the
     
    885909=== stream-butlast-n
    886910
    887  [procedure] (stream-butlast-n stream count)
     911<procedure>(stream-butlast-n stream count)</procedure>
    888912
    889913Returns a stream with all the elements in the
     
    911935=== stream-length
    912936
    913  [procedure] (stream-length str)
     937<procedure>(stream-length str)</procedure>
    914938
    915939Returns the length of the argument stream (a non-negative integer n such that
     
    936960=== stream-length>=
    937961
    938  [procedure] (stream-length>= str len)
     962<procedure>(stream-length>= str len)</procedure>
    939963
    940964Returns {{#t}} if the length of the stream {{str}}
     
    958982=== stream-append
    959983
    960  [procedure] (stream-append str1 str2 ...)
     984<procedure>(stream-append str1 str2 ...)</procedure>
    961985
    962986{{stream-append}} returns a stream consisting of the elements of str1
     
    9861010=== stream-concatenate
    9871011
    988  [procedure] (stream-concatenate str)
     1012<procedure>(stream-concatenate str)</procedure>
    9891013
    9901014...
     
    10001024=== stream-reverse
    10011025
    1002  [procedure] (stream-reverse str)
     1026<procedure>(stream-reverse str)</procedure>
    10031027
    10041028{{stream-reverse}}
     
    10261050=== stream-count
    10271051
    1028  [procedure] (stream-count pred str1 str2 ...)
     1052<procedure>(stream-count pred str1 str2 ...)</procedure>
    10291053
    10301054{{pred}} is a procedure taking as many arguments as there are streams and
     
    11031127=== stream-partition
    11041128
    1105  [procedure] (stream-partition pred str)
     1129<procedure>(stream-partition pred str)</procedure>
    11061130
    11071131Partitions the elements of stream {{str}} with predicate
     
    11281152=== stream-remove
    11291153
    1130  [procedure] (stream-remove pred str)
     1154<procedure>(stream-remove pred str)</procedure>
    11311155
    11321156Returns a stream with all the elements in the stream {{str}}
     
    11501174=== stream-find
    11511175
    1152  [procedure] (stream-find pred str)
     1176<procedure>(stream-find pred str)</procedure>
    11531177
    11541178Return the first element of the stream {{str}}
     
    11811205=== stream-find-tail
    11821206
    1183  [procedure] (stream-find-tail pred str)
     1207<procedure>(stream-find-tail pred str)</procedure>
    11841208
    11851209Returns the first stream-pair of {{str}}
     
    12141238=== stream-take-while
    12151239
    1216  [procedure] (stream-take-while pred str)
     1240<procedure>(stream-take-while pred str)</procedure>
    12171241
    12181242Returns the longest initial prefix of stream {{str}}
     
    12331257=== stream-drop-while
    12341258
    1235  [procedure] (stream-drop-while pred str)
     1259<procedure>(stream-drop-while pred str)</procedure>
    12361260
    12371261Drops the longest initial prefix of stream {{str}} whose
     
    12521276=== stream-span, stream-break
    12531277
    1254  [procedure] (stream-span pred str)
    1255  [procedure] (stream-break pred str)
     1278<procedure>(stream-span pred str)</procedure>
     1279<procedure>(stream-break pred str)</procedure>
    12561280
    12571281{{stream-span}} splits the stream {{str}} into the longest
     
    12901314=== stream-any
    12911315
    1292  [procedure] (stream-any pred str1 str2 ...)
     1316<procedure>(stream-any pred str1 str2 ...)</procedure>
    12931317
    12941318Applies the predicate {{pred}}
     
    13421366=== stream-every
    13431367
    1344  [procedure] (stream-every pred str1 str2 ...)
     1368<procedure>(stream-every pred str1 str2 ...)</procedure>
    13451369
    13461370Applies the predicate across the streams,
     
    13831407=== stream-index
    13841408
    1385  [procedure] (stream-index pred str1 str2 ...)
     1409<procedure>(stream-index pred str1 str2 ...)</procedure>
    13861410
    13871411Return the index of the leftmost elements in the
     
    14221446=== stream-member, stream-memq, stream-memv
    14231447
    1424  [procedure] (stream-member x str [=])
    1425  [procedure] (stream-memq x str)
    1426  [procedure] (stream-memv x str)
     1448<procedure>(stream-member x str [=])</procedure>
     1449<procedure>(stream-memq x str)</procedure>
     1450<procedure>(stream-memv x str)</procedure>
    14271451
    14281452These procedures return the first substream of the
     
    14861510=== stream-sort
    14871511
    1488  [procedure] (stream-sort str <)
     1512<procedure>(stream-sort str <)</procedure>
    14891513
    14901514Returns a copy of {{str}} with its elements sorted.
     
    15051529== Strings as streams
    15061530
    1507 === stream-downcase
    1508 
    1509  [procedure] (stream-downcase str)
     1531=== stream-downcase, stream-upcase
     1532
     1533<procedure>(stream-downcase str)</procedure>
     1534<procedure>(stream-upcase str)</procedure>
    15101535
    15111536Returns a stream identical to the stream of characters {{str}} but
    1512 with all characters converted to lowercase.
     1537with all characters converted to lowercase or uppercase.
    15131538
    15141539<enscript highlight=scheme filename='stream-ext'>
    15151540(define stream-downcase (cut stream-map char-downcase <>))
    1516 </enscript>
    1517 
    1518 === stream-upcase
    1519 
    1520  [procedure] (stream-upcase str)
    1521 
    1522 Returns a stream identical to the stream of characters {{str}} but
    1523 with all characters converted to uppercase.
    1524 
    1525 <enscript highlight=scheme filename='stream-ext'>
    15261541(define stream-upcase   (cut stream-map char-upcase   <>))
    15271542</enscript>
    15281543
     1544=== stream-format
     1545
     1546<procedure>(stream-format fmt ...)</procedure>
     1547
     1548Does the same as {{(format #f fmt ...)}},
     1549but returns the result as a stream of characters rather than a string.
     1550
     1551<enscript highlight=scheme filename='stream-ext'>
     1552(define (stream-format fmt . rest)
     1553  (with-output-to-stream
     1554    (lambda ()
     1555      (format #f fmt rest))))
     1556</enscript>
     1557
     1558=== stream-lines
     1559
     1560<procedure>(stream-lines str)</procedure>
     1561
     1562Returns a stream with the lines found in the stream of
     1563characters {{str}}.  Each line is itself returned
     1564as a stream of characters.  It is an error if {{str}} contains
     1565elements that are not characters.
     1566
     1567<enscript highlight=scheme>(stream-lines (stream #\h #\e #\y #\newline #\y #\o #\u))
     1568=> #<stream (#<stream (#\h #\e #\y)> #<stream (#\y #\o #\u)>)></enscript>
     1569
     1570<enscript highlight=scheme filename='stream-ext'>
     1571(define stream-lines (cut stream-split <> (cut equal? <> #\newline)))
     1572</enscript>
     1573
     1574=== stream-unlines
     1575
     1576TODO: Document
     1577
     1578<enscript highlight=scheme filename='stream-ext'>
     1579(define (stream-unlines lines)
     1580  (stream-concatenate (stream-intersperse lines (stream #\newline))))
     1581</enscript>
     1582
    15291583== Deletion
    15301584
    15311585=== stream-delete
    15321586
    1533  [procedure] (stream-delete x str [=])
     1587<procedure>(stream-delete x str [=])</procedure>
    15341588
    15351589{{stream-delete}} returns a stream identical to {{str}}
     
    15611615=== stream-delete-duplicates
    15621616
    1563  [procedure] (stream-delete-duplicates str [=])
     1617<procedure>(stream-delete-duplicates str [=])</procedure>
    15641618
    15651619{{stream-delete-duplicates}} removes duplicate elements from the
Note: See TracChangeset for help on using the changeset viewer.