Changeset 14195 in project


Ignore:
Timestamp:
04/08/09 19:21:59 (11 years ago)
Author:
Kon Lovett
Message:

Release.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/srfi-41

    r14177 r14195  
    33== srfi-41
    44
    5 SRFI-41 for Chicken Scheme.
     5SRFI 41 for Chicken Scheme.
    66
    77[[toc:]]
     
    3737<procedure>(stream-occupied? OBJECT) => BOOLEAN</procedure>
    3838
    39 {{(not (stream-null? OBJECT))}}
     39{{(and (stream? OBJECT) (not (stream-null? OBJECT)))}}
    4040
    4141==== stream-null
    4242
    43 <stream>stream-null</stream>
     43<constant>stream-null</constant>
     44
     45The null stream value.
    4446
    4547==== stream-cons
    4648
    47 <syntax>(stream-cons OBJECT STREAM)</syntax>
     49<syntax>(stream-cons OBJECT STREAM) => STREAM</syntax>
    4850
    4951==== stream-lambda
    5052
    51 <syntax>(stream-lambda FORMALS BODY ...)</syntax>
     53<syntax>(stream-lambda FORMALS BODY ...) => PROCEDURE</syntax>
    5254
    5355==== stream-car
    5456
    55 <procedure>(stream-car STREAM)</procedure>
     57<procedure>(stream-car STREAM) => OBJECT</procedure>
    5658
    5759==== stream-cdr
    5860
    59 <procedure>(stream-cdr STREAM)</procedure>
     61<procedure>(stream-cdr STREAM) => STREAM</procedure>
    6062
    6163
     
    7476==== stream-of
    7577
    76 <syntax>(stream-of EXPRESSION (VARIABLE in STREAM)/(VARIABLE is EXPRESSION)/PREDICATE ...)</syntax>
     78<syntax>(stream-of EXPRESSION (VARIABLE in STREAM)/(VARIABLE is EXPRESSION)/PREDICATE ...) => STREAM</syntax>
     79
     80==== stream-let
     81
     82<syntax>(stream-let TAG ((NAME VALUE)...) BODY...)</syntax>
     83
     84==== stream-match
     85
     86<syntax>(stream-match STREAM-EXPRESSION CLAUSE...)</syntax>
    7787
    7888==== stream
    7989
    80 <syntax>(stream) stream-null)</syntax>
    81 
    82 ==== stream-let
    83 
    84 <syntax>(stream-let TAG ((NAME VALUE)...) BODY...)</syntax>
    85 
    86 ==== stream-match
    87 
    88 <syntax>(stream-match STREAM-EXPRESSION CLAUSE...)</syntax>
     90<syntax>(stream OBJECT...) => STREAM</syntax>
    8991
    9092==== list->stream
    9193
    92 <procedure>(list->stream LIST)</procedure>
     94<procedure>(list->stream LIST) => STREAM</procedure>
    9395
    9496==== port->stream
    9597
    96 <procedure>(port->stream [PORT (current-input-port)])</procedure>
     98<procedure>(port->stream [PORT (current-input-port)]) => STREAM</procedure>
    9799
    98100==== stream->list
    99101
    100 <procedure>(stream->list [COUNT #f] STREAM)</procedure>
     102<procedure>(stream->list [COUNT #f] STREAM) => LIST</procedure>
    101103
    102104==== stream-append
    103105
    104 <procedure>(stream-append STREAM...)</procedure>
     106<procedure>(stream-append STREAM...) => STREAM</procedure>
    105107
    106108==== stream-concat
    107109
    108 <procedure>(stream-concat STREAMS)</procedure>
     110<procedure>(stream-concat STREAM) => STREAM</procedure>
     111
     112Flatten a stream of streams.
    109113
    110114==== stream-drop
    111115
    112 <procedure>(stream-drop N STREAM)</procedure>
     116<procedure>(stream-drop COUNT STREAM) => STREAM</procedure>
    113117
    114118==== stream-drop-while
    115119
    116 <procedure>(stream-drop-while PREDICATE STREAM)</procedure>
     120<procedure>(stream-drop-while PREDICATE STREAM) => STREAM</procedure>
    117121
    118122==== stream-filter
    119123
    120 <procedure>(stream-filter PREDICATE STREAM)</procedure>
     124<procedure>(stream-filter PREDICATE STREAM) => STREAM</procedure>
    121125
    122126==== stream-fold
    123127
    124 <procedure>(stream-fold PROCEDURE BASE STREAM...)</procedure>
     128<procedure>(stream-fold PROCEDURE BASE STREAM...) => OBJECT</procedure>
    125129
    126130==== stream-for-each
    127131
    128 <procedure>(stream-for-each PROCEDURE STREAM...)</procedure>
     132<procedure>(stream-for-each PROCEDURE STREAM...) => STREAM</procedure>
    129133
    130134==== stream-map
    131135
    132 <procedure>(stream-map PROCEDURE STREAM...)</procedure>
     136<procedure>(stream-map PROCEDURE STREAM...) => STREAM</procedure>
    133137
    134138==== stream-from
    135139
    136 <procedure>(stream-from FIRST [STEP 1])</procedure>
     140<procedure>(stream-from FIRST [STEP 1]) => STREAM</procedure>
    137141
    138142==== stream-iterate
    139143
    140 <procedure>(stream-iterate PROCEDURE BASE)</procedure>
     144<procedure>(stream-iterate PROCEDURE BASE) => STREAM</procedure>
    141145
    142146==== stream-length
    143147
    144 <procedure>(stream-length STREAM)</procedure>
     148<procedure>(stream-length STREAM) => FIXNUM</procedure>
    145149
    146150==== stream-range
    147151
    148 <procedure>(stream-range FIRST PAST [STEP (if (< FIRST PAST) 1 -1)])</procedure>
     152<procedure>(stream-range FIRST PAST [STEP (if (< FIRST PAST) 1 -1)]) => STREAM</procedure>
    149153
    150154==== stream-ref
    151155
    152 <procedure>(stream-ref STREAM INDEX)</procedure>
     156<procedure>(stream-ref STREAM INDEX) => OBJECT</procedure>
    153157
    154158==== stream-reverse
    155159
    156 <procedure>(stream-reverse STREAM)</procedure>
     160<procedure>(stream-reverse STREAM) => STREAM</procedure>
    157161
    158162==== stream-scan
    159163
    160 <procedure>(stream-scan PROCEDURE BASE STREAM)</procedure>
    161 
    162 ==== stream-take
    163 
    164 <procedure>(stream-take N STREAM)</procedure>
    165 
    166 ==== stream-take-while
    167 
    168 <procedure>(stream-take-while PREDICATE STREAM)</procedure>
     164<procedure>(stream-scan PROCEDURE BASE STREAM) => STREAM</procedure>
    169165
    170166==== stream-unfold
    171167
    172 <procedure>(stream-unfold MAPPER PREDICATE GENERATOR BASE)</procedure>
     168<procedure>(stream-unfold MAPPER PREDICATE GENERATOR BASE) => STREAM</procedure>
    173169
    174170==== stream-unfolds
    175171
    176 <procedure>(stream-unfolds GENERATOR SEED)</procedure>
     172<procedure>(stream-unfolds GENERATOR SEED) => STREAM</procedure>
    177173
    178174==== stream-zip
    179175
    180 <procedure>(stream-zip STREAM...)</procedure>
     176<procedure>(stream-zip STREAM...) => STREAM</procedure>
    181177
    182178
     
    191187==== stream-intersperse
    192188
    193 <stream>(stream-intersperse STREAM OBJECT)</stream>
     189<procedure>(stream-intersperse STREAM OBJECT) => STREAM</procedure>
    194190
    195191==== stream-permutations
    196192
    197 <stream>(stream-permutations STREAM)</stream>
     193<procedure>(stream-permutations STREAM) => STREAM</procedure>
    198194
    199195==== file->stream
    200196
    201 <stream>(file->stream FILENAME [READ-PROCEDURE read-char])</stream>
     197<procedure>(file->stream FILENAME [READ-PROCEDURE read-char]) => STREAM</procedure>
    202198
    203199==== stream-split
    204200
    205 <procedure>(stream-split N STREAM)</procedure>
     201<procedure>(stream-split COUNT STREAM) => (values STREAM STREAM)</procedure>
    206202
    207203==== stream-unique
    208204
    209 <stream>(stream-unique EQUIVALENCE STREAM)</stream>
     205<procedure>(stream-unique EQUIVALENCE STREAM) => STREAM</procedure>
    210206
    211207==== stream-fold-one
    212208
    213 <procedure>(stream-fold-one FUNCTION STREAM)</procedure>
     209<procedure>(stream-fold-one FUNCTION STREAM) => STREAM</procedure>
    214210
    215211==== stream-member
    216212
    217 <stream>(stream-member EQUIVALENCE OBJECT STREAM)</stream>
     213<procedure>(stream-member EQUIVALENCE OBJECT STREAM) => STREAM</procedure>
    218214
    219215==== stream-merge
    220216
    221 <stream>(stream-merge LESS-THAN STREAM ...)</stream>
     217<procedure>(stream-merge LESS-THAN STREAM ...) => STREAM</procedure>
    222218
    223219==== stream-partition
    224220
    225 <procedure>(stream-partition PREDICATE STREAM)</procedure>
     221<procedure>(stream-partition PREDICATE STREAM) => STREAM</procedure>
    226222
    227223==== stream-finds
    228224
    229 <stream>(stream-finds EQUIVALENCE OBJECT STREAM)</stream>
     225<procedure>(stream-finds EQUIVALENCE OBJECT STREAM) => STREAM</procedure>
    230226
    231227==== stream-find
    232228
    233 <procedure>(stream-find EQUIVALENCE OBJECT STREAM)</procedure>
     229<procedure>(stream-find EQUIVALENCE OBJECT STREAM) => STREAM</procedure>
    234230
    235231==== stream-remove
    236232
    237 <stream>(stream-remove PREDICATE STREAM)</stream>
     233<procedure>(stream-remove PREDICATE STREAM) => STREAM</procedure>
    238234
    239235==== stream-every
    240236
    241 <procedure>(stream-every PREDICATE STREAM)</procedure>
     237<procedure>(stream-every PREDICATE STREAM) => BOOLEAN</procedure>
    242238
    243239==== stream-any
    244240
    245 <procedure>(stream-any PREDICATE STREAM)</procedure>
     241<procedure>(stream-any PREDICATE STREAM) => BOOLEAN</procedure>
    246242
    247243==== stream-and
    248244
    249 <procedure>(stream-and STREAM)</procedure>
     245<procedure>(stream-and STREAM) => BOOLEAN</procedure>
    250246
    251247==== stream-or
    252248
    253 <procedure>(stream-or STREAM)</procedure>
     249<procedure>(stream-or STREAM) => BOOLEAN</procedure>
    254250
    255251==== stream-fold-right
    256252
    257 <procedure>(stream-fold-right FUNCTION BASE STREAM)</procedure>
     253<procedure>(stream-fold-right FUNCTION BASE STREAM) => OBJECT</procedure>
    258254
    259255==== stream-fold-right-one
    260256
    261 <procedure>(stream-fold-right-one FUNCTION STREAM)</procedure>
     257<procedure>(stream-fold-right-one FUNCTION STREAM) => OBJECT</procedure>
    262258
    263259==== stream-assoc
    264260
    265 <procedure>(stream-assoc KEY STREAM)</procedure>
     261<procedure>(stream-assoc KEY STREAM [EQUIVALENCE equal?]) => OBJECT</procedure>
    266262
    267263==== stream-equal?
    268264
    269 <procedure>(stream-equal? EQUIVALENCE STREAM1 STREAM2)</procedure>
     265<procedure>(stream-equal? EQUIVALENCE STREAM1 STREAM2) => BOOLEAN</procedure>
    270266
    271267==== stream-quick-sort
    272268
    273 <stream>(stream-quick-sort LESS-THAN STREAM)</stream>
     269<procedure>(stream-quick-sort LESS-THAN STREAM) => STREAM</procedure>
    274270
    275271==== stream-insertion-sort
    276272
    277 <stream>(stream-insertion-sort LESS-THAN STREAM)</stream>
     273<procedure>(stream-insertion-sort LESS-THAN STREAM) => STREAM</procedure>
    278274
    279275==== stream-merge-sort
    280276
    281 <stream>(stream-merge-sort LESS-THAN STREAM)</stream>
     277<procedure>(stream-merge-sort LESS-THAN STREAM) => STREAM</procedure>
    282278
    283279==== stream-maximum
    284280
    285 <procedure>(stream-maximum LESS-THAN STREAM)</procedure>
     281<procedure>(stream-maximum LESS-THAN STREAM) => OBJECT</procedure>
    286282
    287283==== stream-minimum
    288284
    289 <procedure>(stream-minimum LESS-THAN STREAM)</procedure>
     285<procedure>(stream-minimum LESS-THAN STREAM) => OBJECT</procedure>
    290286
    291287
     
    298294</enscript>
    299295
     296==== stream-max
     297
     298<procedure>(stream-max STREAM) => OBJECT</procedure>
     299
     300==== stream-min
     301
     302<procedure>(stream-min STREAM) => OBJECT</procedure>
     303
    300304==== stream-sum
    301305
    302 <stream>stream-sum</stream>
    303 
    304 ==== stream-max
    305 
    306 <procedure>(stream-max STREAM)</procedure>
    307 
    308 ==== stream-min
    309 
    310 <procedure>(stream-min STREAM)</procedure>
     306<constant>stream-sum</constant>
    311307
    312308==== odd-numbers-stream
    313309
    314 <stream>odd-numbers-stream</stream>
     310<constant>odd-numbers-stream</constant>
    315311
    316312==== even-numbers-stream
    317313
    318 <stream>even-numbers-stream</stream>
     314<constant>even-numbers-stream</constant>
     315
     316==== cardinal-numbers-stream
     317
     318<constant>cardinal-numbers-stream</constant>
    319319
    320320==== natural-numbers-stream
    321321
    322 <stream>natural-numbers-stream</stream>
     322<constant>natural-numbers-stream</constant>
    323323
    324324==== prime-numbers-stream
    325325
    326 <stream>prime-numbers-stream</stream>
     326<constant>prime-numbers-stream</constant>
    327327
    328328==== hamming-sequence-stream
    329329
    330 <stream>hamming-sequence-stream</stream>
     330<constant>hamming-sequence-stream</constant>
    331331
    332332
     
    343343(require-extension streams)
    344344
    345 (define (sigma FUNCTION m n)
    346   (stream-fold + 0 (stream-map FUNCTION (stream-range m (+ n 1)))))
     345(define (sigma function m n)
     346  (stream-fold + 0 (stream-map function (stream-range m (add1 n)))))
    347347
    348348(define (factorial n)
    349349  (stream-ref (stream-scan * 1 (stream-from 1))) n)
    350 
    351 (define odd-numbers-stream (stream-from 1 2))
    352 
    353 (define even-numbers-stream (stream-from 0 2))
    354 
    355 (define natural-numbers-stream (stream-iterate add1 0))
    356 
    357 (define prime-numbers-stream
    358   (define-stream (next base mult STREAM)
    359     (let ((first (stream-car STREAM))
    360           (rest (stream-cdr STREAM)))
    361       (cond ((< first mult)
    362               (stream-cons first (next base mult rest)))
    363             ((< mult first)
    364               (next base (+ base mult) STREAM))
    365             (else (next base (+ base mult) rest)))))
    366   (define-stream (sift base STREAM)
    367     (next base (+ base base) STREAM))
    368   (define-stream (sieve STREAM)
    369     (let ((first (stream-car STREAM))
    370           (rest (stream-cdr STREAM)))
    371       (stream-cons first (sieve (sift first rest)))))
    372   (sieve (stream-from 2)))
    373 
    374 ;; http://www.research.att.com/~njas/sequences/A051037
    375 
    376 (define hamming-sequence-stream
    377   (stream-cons 1
    378     (stream-unique =
    379       (stream-merge <
    380         (stream-map (left-section * 2) hamming-sequence-stream)
    381         (stream-map (left-section * 3) hamming-sequence-stream)
    382         (stream-map (left-section * 5) hamming-sequence-stream)))))
    383350</enscript>
    384351
Note: See TracChangeset for help on using the changeset viewer.