[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What?
Am Sonntag den, 11. August 2002, um 14:30, schrieb Rainer Joswig:
>>
>> Something like this would be interesting:
>>
>> define method read-lines ( stream )
>> choose-until(identity, lazy-sequence(curry(read-line, stream,
>> on-end-of-stream: #f )))
>> end;
>>
>> With appropriate definitions of choose-until and lazy-sequence.
>
> Using the series package from Richard Waters it would be something
> like this (just a raw version):
>
> (defun sum-stream (stream)
> (series:collect-sum
> (series:map-fn 'string
> #'parse-integer
> (series:scan-fn t
> (lambda ()
> (read-line stream nil nil))
> (lambda (ignore)
> (read-line stream nil nil))
> #'null))))
>
In Dylan you would do it using forward-iteration-protocol on
<lazy-sequence>:
forward-iteration-protocol collection
=> initial-state limit next-state finished-state? current-key
current-element current-element-setter copy-state
The next-state function would call the read-line,
finished-state? related information could be supplied by
lazy-sequence(curry(read-line, stream, on-end-of-stream: #f ),
finished?: identity)
this would also eliminate the \choose-until.
Time to write this down into the Wiki.
Gabor
- References:
- Re: What?
- From: Rainer Joswig <joswig@lispmachine.de>