[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
util.stream
- ストリームライブラリ このモジュールは遅延ストリームのライブラリを提供します。このモジュール には SRFI-40 で定義されている関数および構文が含まれています。
[SRFI-40]
objがutil.stream
の手続きによって作成されたストリームであ
る場合にかぎり#t
を返します。
[SRFI-40] NULLストリームのシングルトンインスタンス。
[SRFI-40] ストリームの基本構成子。objectをstreamの先頭に追加し、新し いストリームを返します。
[SRFI-40]
objがNULLストリームの場合にのみ#t
を返します。
[SRFI-40]
objがNULLストリームではないストリームのときにのみ#t
を返します。
[SRFI-40] ストリームsの最初の要素を返します。
[SRFI-40] ストリームsの最初の要素をのぞいたのこりの要素をストリームとして 返します。
[SRFI-40] exprの遅延形式であるストリームを返します。
原則として、ストリームを生成する関数はすべからく結果を
stream-delay
でラップすべきです。
[SRFI-40] 要素がobj …であるような新しいストリームを返します。
[SRFI-40] 互いに関連する n 本のストリームを生成します。それぞれの内容は generatorおよびseedを使って生成します。
generatorは現在のシード値とともに呼ばれ、n+1
個の値
を返します。
(generator seed) => seed result_0 result_1 … result_n-1 |
最初の値は次のシード値になります。Result_kは以下の形式のどれかで なければなりません。
(val)
valはk-番目のストリームの次のcar部になります。
#f
k-番目のストリームの新しい情報はありません。
()
k-番目のストリームの最後に到達しました。
以下の例では2つのストリームが作られます。最初のものは奇数の無限ストリー ムで、2つめのものは偶数の無限ストリームです。
gosh> (define-values (s0 s1) (stream-unfoldn (lambda (i) (values (+ i 2) ;; next seed (list i) ;; for the first stream (list (+ i 1)))) ;; for the second stream 0 2)) #<undef> gosh> (stream->list (stream-take s0 10)) (0 2 4 6 8 10 12 14 16 18) gosh> (stream->list (stream-take s1 10)) (1 3 5 7 9 11 13 15 17 19) |
[SRFI-40] streamsの各要素にfuncを適用した値を要素とする新しいストリー ムを返します。
[SRFI-40] funcをstreamsの各要素に適用します。 streamsが終端にたっしたところで停止します。
[SRFI-40] pred?をパスする要素のみからなる新しいストリームを返す。
以下の手続きは Alejandro Forero Cuervo が Chicken Schemeのために書いた
ライブラリから取ってきたものです。これらの手続きの名前は srfi-1
(srfi-1
- List library)の命名規則にならったものです。
(stream-cons b a)
のこと。利便性のためだけにある。
streamの前にelt …を連結した新しいストリームを生成し ます。
n個のinitを要素とする新しいストリームを生成します。
initが省略された場合#f
が使われます。nを負の値にする
と無限ストリームが生成されます。
n個の要素をもつ新しいストリームを生成します。k-番目の要素 は init-proc を k に適用して得られます。nを負の値にする と無限ストリームが生成されます。
startからはじまり、stepずつ要素が増加する整数のストリーム を生成します。ストリームの長さはcountが正ならその値になります。 countが負なら無限ストリームになります。startのデフォルト値 は 0、stepのデフォルト値は 1 です。
string->stream
を(format fmt arg …)
に適用した結果の
ストリームを返します。
Converts a stream to a list or a string. All of stream's
elements are force
d; if stream is infinite, these
procedures won't terminate. For stream->string
,
all stream must be characters, or an error is signalled.
Converts a list to a stream of its elements.
Convers a string to a stream of characters. If an optional stream is given, it becomes the tail of the resulting stream.
(stream->list (string->stream "abc" (list->stream '(1 2 3)))) ⇒ (#\a #\b #\c 1 2 3)
Creates a stream, whose elements consist of the items
read from the input port iport.
The default iport is the current input port.
The default reader is read-char
.
The result stream terminates at the point where reader returns EOF (EOF itself is not included in the stream). If closer is given, it is called with iport as an argument just after reader reads EOF.
A generic procedure to turn an internal iterator iter into a stream of iterated results.
The iter argument is a procedure that takes two arguments, next and end, where next is a procedure that takes one argument and end is a thunk. Iter is supposed to iterate over some set and call next for each argument, then call end to indicate the end of the iteration. Here's a contrived example:
(stream->list (iterator->stream (lambda (next end) (for-each next '(1 2 3 4 5)) (end)))) ⇒ (1 2 3 4 5) |
Internally iterator->stream
uses the “inversion of iterator”
technique, so that iter only iterates to the element that
are needed by the stream. Thus iter can iterate over
an infinite set. In the following example, iter is
an infinite loop calling next with increasing integers,
but only the first 10 elements are calculated because of
stream-take
:
(stream->list (stream-take (iterator->stream (lambda (next end) (let loop ((n 0)) (next n) (loop (+ n 1))))) 10)) ⇒ (0 1 2 3 4 5 6 7 8 9) |
Splits stream where its element equals to #\n
, and
returns a stream of splitted streams.
(stream->list (stream-map stream->string (stream-lines (string->stream "abc\ndef\nghi")))) ⇒ ("abc" "def" "ghi") |
Returns true iff each corresponding element of stream … are the same in terms of elt=. This procedure won't terminate if any of streams is infinite.
Compares initial elements of stream against a list prefix by elt=. Only as many elements of stream as prefix has are checked.
…
(stream-caar s)
= (stream-car (stream-car s))
etc.
Returns the pos-th element in the stream. Pos must be a nonnegative exact integer.
(stream-first s)
= (stream-ref s 0)
etc.
Returns a new stream that consists of the first count elements
of the given stream. If the given stream has less than
count elements, the stream returned by stream-take
would raise an error when the elements beyond the original stream
is accessed. On the other hand, the stream returned by
stream-take-safe
will return a shortened stream when
the given steram has less than count elements.
(stream->list (stream-take (stream-iota -1) 10)) ⇒ (0 1 2 3 4 5 6 7 8 9) (stream-take (stream 1 2) 5) ⇒ stream (stream->list (stream-take (stream 1 2) 5)) ⇒ error (stream->list (stream-take-safe (stream 1 2) 5)) ⇒ (1 2) |
Returns a new stream that consists of the elements in the given
stream except the first count elements.
If the given stream has less than count elements,
stream-drop
returns a stream that raises an error
if its element is accessed, and stream-drop-safe
returns an empty stream.
Returns a new stream in which element is inserted between elements of stream.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Shiro Kawai on November, 22 2009 using texi2html 1.78.