[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: streams are cool, you could stream virtually anything!
From: |
Phillip Lord |
Subject: |
Re: streams are cool, you could stream virtually anything! |
Date: |
Wed, 04 Nov 2015 17:00:03 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
At the risk of this sounding like a plug, it was my desire to get away
from looping that motivated my own library m-buffer
(https://github.com/phillord/m-buffer-el). This is not lazy, but is list
based.
I'd have a couple of questions with this approach. First, what happens
if the lambda *changes* the buffer? Mixing this form of mutability with
laziness is, I think, going to be unpredictable.
Second question, what happens to the match data? How would you deal with
nil'ing markers after use? Otherwise, you're going to fill the buffer up
with markers (they do GC, but slowly).
Phil
Nicolas Petton <address@hidden> writes:
> Hi guys,
>
> Aren't you tired of writing the same for loops in various contexts?
> I know I was, and there's a better way!
>
> I just added a function `stream-regexp' to stream.el to stream the
> search of a regexp in a buffer:
>
>
> (let ((str (stream-regexp buf ".*foo\\(.*\\)$")))
> (seq-map (lambda (match-data)
> ...)
> str))
>
> (I still have to document it and test it properly)
>
> Because streams are lazy and immutable, you can reuse such a stream
> forever or keep it for later, move around in a buffer or modify the
> buffer and re-evaluate the stream (you'll get new match data), or map
> the result, etc.
>
> All the credit goes to Damien Cassou for giving me the idea :-)
>
> Cheers,
> Nico
- Re: streams are cool, you could stream virtually anything!, (continued)
- Re: streams are cool, you could stream virtually anything!, Nicolas Petton, 2015/11/06
- Re: streams are cool, you could stream virtually anything!, John Wiegley, 2015/11/06
- Re: streams are cool, you could stream virtually anything!, Nicolas Petton, 2015/11/06
- Re: streams are cool, you could stream virtually anything!, John Wiegley, 2015/11/06
- Re: streams are cool, you could stream virtually anything!, Nicolas Petton, 2015/11/06
- Re: streams are cool, you could stream virtually anything!, Artur Malabarba, 2015/11/05
- Re: streams are cool, you could stream virtually anything!, Michael Heerdegen, 2015/11/05
Re: streams are cool, you could stream virtually anything!,
Phillip Lord <=
Re: streams are cool, you could stream virtually anything!, Michael Heerdegen, 2015/11/04