Artifact
a9e0ae806011dceb81b63e3c2b0cba47c79729ee:
- File
srfi/s41/streams.sls
— part of check-in
[80c8c83034]
at
2016-07-07 18:11:39
on branch trunk
— initial import
(user:
ovenpasta@pizzahack.eu
size: 1827)
0000: 23 21 72 36 72 73 20 0a 3b 3b 3b 20 43 6f 70 79 #!r6rs .;;; Copy
0010: 72 69 67 68 74 20 28 43 29 20 50 68 69 6c 69 70 right (C) Philip
0020: 20 4c 2e 20 42 65 77 69 67 20 28 32 30 30 37 29 L. Bewig (2007)
0030: 2e 20 41 6c 6c 20 52 69 67 68 74 73 20 52 65 73 . All Rights Res
0040: 65 72 76 65 64 2e 0a 3b 3b 3b 20 50 65 72 6d 69 erved..;;; Permi
0050: 73 73 69 6f 6e 20 69 73 20 68 65 72 65 62 79 20 ssion is hereby
0060: 67 72 61 6e 74 65 64 2c 20 66 72 65 65 20 6f 66 granted, free of
0070: 20 63 68 61 72 67 65 2c 20 74 6f 20 61 6e 79 20 charge, to any
0080: 70 65 72 73 6f 6e 0a 3b 3b 3b 20 6f 62 74 61 69 person.;;; obtai
0090: 6e 69 6e 67 20 61 20 63 6f 70 79 20 6f 66 20 74 ning a copy of t
00a0: 68 69 73 20 73 6f 66 74 77 61 72 65 20 61 6e 64 his software and
00b0: 20 61 73 73 6f 63 69 61 74 65 64 20 64 6f 63 75 associated docu
00c0: 6d 65 6e 74 61 74 69 6f 6e 20 66 69 6c 65 73 0a mentation files.
00d0: 3b 3b 3b 20 28 74 68 65 20 22 53 6f 66 74 77 61 ;;; (the "Softwa
00e0: 72 65 22 29 2c 20 74 6f 20 64 65 61 6c 20 69 6e re"), to deal in
00f0: 20 74 68 65 20 53 6f 66 74 77 61 72 65 20 77 69 the Software wi
0100: 74 68 6f 75 74 20 72 65 73 74 72 69 63 74 69 6f thout restrictio
0110: 6e 2c 0a 3b 3b 3b 20 69 6e 63 6c 75 64 69 6e 67 n,.;;; including
0120: 20 77 69 74 68 6f 75 74 20 6c 69 6d 69 74 61 74 without limitat
0130: 69 6f 6e 20 74 68 65 20 72 69 67 68 74 73 20 74 ion the rights t
0140: 6f 20 75 73 65 2c 20 63 6f 70 79 2c 20 6d 6f 64 o use, copy, mod
0150: 69 66 79 2c 20 6d 65 72 67 65 2c 0a 3b 3b 3b 20 ify, merge,.;;;
0160: 70 75 62 6c 69 73 68 2c 20 64 69 73 74 72 69 62 publish, distrib
0170: 75 74 65 2c 20 73 75 62 6c 69 63 65 6e 73 65 2c ute, sublicense,
0180: 20 61 6e 64 2f 6f 72 20 73 65 6c 6c 20 63 6f 70 and/or sell cop
0190: 69 65 73 20 6f 66 20 74 68 65 20 53 6f 66 74 77 ies of the Softw
01a0: 61 72 65 2c 0a 3b 3b 3b 20 61 6e 64 20 74 6f 20 are,.;;; and to
01b0: 70 65 72 6d 69 74 20 70 65 72 73 6f 6e 73 20 74 permit persons t
01c0: 6f 20 77 68 6f 6d 20 74 68 65 20 53 6f 66 74 77 o whom the Softw
01d0: 61 72 65 20 69 73 20 66 75 72 6e 69 73 68 65 64 are is furnished
01e0: 20 74 6f 20 64 6f 20 73 6f 2c 0a 3b 3b 3b 20 73 to do so,.;;; s
01f0: 75 62 6a 65 63 74 20 74 6f 20 74 68 65 20 66 6f ubject to the fo
0200: 6c 6c 6f 77 69 6e 67 20 63 6f 6e 64 69 74 69 6f llowing conditio
0210: 6e 73 3a 0a 3b 3b 3b 20 0a 3b 3b 3b 20 54 68 65 ns:.;;; .;;; The
0220: 20 61 62 6f 76 65 20 63 6f 70 79 72 69 67 68 74 above copyright
0230: 20 6e 6f 74 69 63 65 20 61 6e 64 20 74 68 69 73 notice and this
0240: 20 70 65 72 6d 69 73 73 69 6f 6e 20 6e 6f 74 69 permission noti
0250: 63 65 20 73 68 61 6c 6c 20 62 65 0a 3b 3b 3b 20 ce shall be.;;;
0260: 69 6e 63 6c 75 64 65 64 20 69 6e 20 61 6c 6c 20 included in all
0270: 63 6f 70 69 65 73 20 6f 72 20 73 75 62 73 74 61 copies or substa
0280: 6e 74 69 61 6c 20 70 6f 72 74 69 6f 6e 73 20 6f ntial portions o
0290: 66 20 74 68 65 20 53 6f 66 74 77 61 72 65 2e 0a f the Software..
02a0: 3b 3b 3b 20 0a 3b 3b 3b 20 54 48 45 20 53 4f 46 ;;; .;;; THE SOF
02b0: 54 57 41 52 45 20 49 53 20 50 52 4f 56 49 44 45 TWARE IS PROVIDE
02c0: 44 20 22 41 53 20 49 53 22 2c 20 57 49 54 48 4f D "AS IS", WITHO
02d0: 55 54 20 57 41 52 52 41 4e 54 59 20 4f 46 20 41 UT WARRANTY OF A
02e0: 4e 59 20 4b 49 4e 44 2c 0a 3b 3b 3b 20 45 58 50 NY KIND,.;;; EXP
02f0: 52 45 53 53 20 4f 52 20 49 4d 50 4c 49 45 44 2c RESS OR IMPLIED,
0300: 20 49 4e 43 4c 55 44 49 4e 47 20 42 55 54 20 4e INCLUDING BUT N
0310: 4f 54 20 4c 49 4d 49 54 45 44 20 54 4f 20 54 48 OT LIMITED TO TH
0320: 45 20 57 41 52 52 41 4e 54 49 45 53 20 4f 46 0a E WARRANTIES OF.
0330: 3b 3b 3b 20 4d 45 52 43 48 41 4e 54 41 42 49 4c ;;; MERCHANTABIL
0340: 49 54 59 2c 20 46 49 54 4e 45 53 53 20 46 4f 52 ITY, FITNESS FOR
0350: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
0360: 52 50 4f 53 45 20 41 4e 44 0a 3b 3b 3b 20 4e 4f RPOSE AND.;;; NO
0370: 4e 49 4e 46 52 49 4e 47 45 4d 45 4e 54 2e 20 49 NINFRINGEMENT. I
0380: 4e 20 4e 4f 20 45 56 45 4e 54 20 53 48 41 4c 4c N NO EVENT SHALL
0390: 20 54 48 45 20 41 55 54 48 4f 52 53 20 4f 52 20 THE AUTHORS OR
03a0: 43 4f 50 59 52 49 47 48 54 20 48 4f 4c 44 45 52 COPYRIGHT HOLDER
03b0: 53 0a 3b 3b 3b 20 42 45 20 4c 49 41 42 4c 45 20 S.;;; BE LIABLE
03c0: 46 4f 52 20 41 4e 59 20 43 4c 41 49 4d 2c 20 44 FOR ANY CLAIM, D
03d0: 41 4d 41 47 45 53 20 4f 52 20 4f 54 48 45 52 20 AMAGES OR OTHER
03e0: 4c 49 41 42 49 4c 49 54 59 2c 20 57 48 45 54 48 LIABILITY, WHETH
03f0: 45 52 20 49 4e 20 41 4e 0a 3b 3b 3b 20 41 43 54 ER IN AN.;;; ACT
0400: 49 4f 4e 20 4f 46 20 43 4f 4e 54 52 41 43 54 2c ION OF CONTRACT,
0410: 20 54 4f 52 54 20 4f 52 20 4f 54 48 45 52 57 49 TORT OR OTHERWI
0420: 53 45 2c 20 41 52 49 53 49 4e 47 20 46 52 4f 4d SE, ARISING FROM
0430: 2c 20 4f 55 54 20 4f 46 20 4f 52 20 49 4e 0a 3b , OUT OF OR IN.;
0440: 3b 3b 20 43 4f 4e 4e 45 43 54 49 4f 4e 20 57 49 ;; CONNECTION WI
0450: 54 48 20 54 48 45 20 53 4f 46 54 57 41 52 45 20 TH THE SOFTWARE
0460: 4f 52 20 54 48 45 20 55 53 45 20 4f 52 20 4f 54 OR THE USE OR OT
0470: 48 45 52 20 44 45 41 4c 49 4e 47 53 20 49 4e 20 HER DEALINGS IN
0480: 54 48 45 0a 3b 3b 3b 20 53 4f 46 54 57 41 52 45 THE.;;; SOFTWARE
0490: 2e 0a 0a 28 6c 69 62 72 61 72 79 20 28 73 72 66 ...(library (srf
04a0: 69 20 73 34 31 20 73 74 72 65 61 6d 73 29 0a 0a i s41 streams)..
04b0: 20 20 28 65 78 70 6f 72 74 20 73 74 72 65 61 6d (export stream
04c0: 2d 6e 75 6c 6c 20 73 74 72 65 61 6d 2d 63 6f 6e -null stream-con
04d0: 73 20 73 74 72 65 61 6d 3f 20 73 74 72 65 61 6d s stream? stream
04e0: 2d 6e 75 6c 6c 3f 20 73 74 72 65 61 6d 2d 70 61 -null? stream-pa
04f0: 69 72 3f 20 73 74 72 65 61 6d 2d 63 61 72 0a 20 ir? stream-car.
0500: 20 20 20 20 20 20 20 20 20 73 74 72 65 61 6d 2d stream-
0510: 63 64 72 20 73 74 72 65 61 6d 2d 6c 61 6d 62 64 cdr stream-lambd
0520: 61 20 64 65 66 69 6e 65 2d 73 74 72 65 61 6d 20 a define-stream
0530: 6c 69 73 74 2d 3e 73 74 72 65 61 6d 20 70 6f 72 list->stream por
0540: 74 2d 3e 73 74 72 65 61 6d 20 73 74 72 65 61 6d t->stream stream
0550: 0a 20 20 20 20 20 20 20 20 20 20 73 74 72 65 61 . strea
0560: 6d 2d 3e 6c 69 73 74 20 73 74 72 65 61 6d 2d 61 m->list stream-a
0570: 70 70 65 6e 64 20 73 74 72 65 61 6d 2d 63 6f 6e ppend stream-con
0580: 63 61 74 20 73 74 72 65 61 6d 2d 63 6f 6e 73 74 cat stream-const
0590: 61 6e 74 20 73 74 72 65 61 6d 2d 64 72 6f 70 0a ant stream-drop.
05a0: 20 20 20 20 20 20 20 20 20 20 73 74 72 65 61 6d stream
05b0: 2d 64 72 6f 70 2d 77 68 69 6c 65 20 73 74 72 65 -drop-while stre
05c0: 61 6d 2d 66 69 6c 74 65 72 20 73 74 72 65 61 6d am-filter stream
05d0: 2d 66 6f 6c 64 20 73 74 72 65 61 6d 2d 66 6f 72 -fold stream-for
05e0: 2d 65 61 63 68 20 73 74 72 65 61 6d 2d 66 72 6f -each stream-fro
05f0: 6d 0a 20 20 20 20 20 20 20 20 20 20 73 74 72 65 m. stre
0600: 61 6d 2d 69 74 65 72 61 74 65 20 73 74 72 65 61 am-iterate strea
0610: 6d 2d 6c 65 6e 67 74 68 20 73 74 72 65 61 6d 2d m-length stream-
0620: 6c 65 74 20 73 74 72 65 61 6d 2d 6d 61 70 20 73 let stream-map s
0630: 74 72 65 61 6d 2d 6d 61 74 63 68 0a 20 20 20 20 tream-match.
0640: 20 20 20 20 20 20 73 74 72 65 61 6d 2d 6f 66 20 stream-of
0650: 73 74 72 65 61 6d 2d 72 61 6e 67 65 20 73 74 72 stream-range str
0660: 65 61 6d 2d 72 65 66 20 73 74 72 65 61 6d 2d 72 eam-ref stream-r
0670: 65 76 65 72 73 65 20 73 74 72 65 61 6d 2d 73 63 everse stream-sc
0680: 61 6e 20 73 74 72 65 61 6d 2d 74 61 6b 65 0a 20 an stream-take.
0690: 20 20 20 20 20 20 20 20 20 73 74 72 65 61 6d 2d stream-
06a0: 74 61 6b 65 2d 77 68 69 6c 65 20 73 74 72 65 61 take-while strea
06b0: 6d 2d 75 6e 66 6f 6c 64 20 73 74 72 65 61 6d 2d m-unfold stream-
06c0: 75 6e 66 6f 6c 64 73 20 73 74 72 65 61 6d 2d 7a unfolds stream-z
06d0: 69 70 29 0a 0a 20 20 28 69 6d 70 6f 72 74 20 28 ip).. (import (
06e0: 73 72 66 69 20 73 34 31 20 73 74 72 65 61 6d 73 srfi s41 streams
06f0: 20 70 72 69 6d 69 74 69 76 65 29 0a 20 20 20 20 primitive).
0700: 20 20 20 20 20 20 28 73 72 66 69 20 73 34 31 20 (srfi s41
0710: 73 74 72 65 61 6d 73 20 64 65 72 69 76 65 64 29 streams derived)
0720: 29 29 0a )).