IRC channel logs

2020-06-27.log

back to list of logs

***logicmoo is now known as dmiles
***wxie1 is now known as wxie
***apteryx is now known as Guest55957
***apteryx_ is now known as apteryx
<mwette>o/
***heisenberg-25 is now known as Habush
<wklew>is there a Guile library like haskell's "foldl"? https://hackage.haskell.org/package/foldl
<wklew>I'm looking to do stream processing with "fusion", i.e. composing filter, map, take etc in constant memory
<wklew>SRFI-41 doesn't mention whether it supports this
<wklew>for example, take the first 10 elements of a possibly infinite stream and perform a left fold on them, in a single pass
<rgherdt>isn't this what SRFI-41's stream-fold does?
<wklew>well the goal is to build a complex fold from composable, simple folds
<wklew>that's what the foldl haskell library does
<wklew>e.g. `(fold-left + 0 (take 10 ...))`
<wklew>we would rather not accumulate those 10 values in memory and then pass them to fold-left, rather it would all be done in one pass
*wklew actually reads the SRFI docs...
<rgherdt>SRFI-41 states "if the intermediate result is stored as a stream, it can be generated piecemeal, using only as much memory as required by a single item."
<rgherdt>so as I understand it should do what you want
<rgherdt>your example: (stream-fold + 0 (stream-take 10 (stream-range 0 100)))
<wklew>excellent! that's exactly what I was hoping
<wklew>now I'm trying to wrap my head around representing a lazy tree as a stream
<leoprikler>assuming you want all items eventually, you can do a stream-lambda implementing a BFS
<leoprikler>(or DFS if you prefer)
<leoprikler>otherwise it might be simpler to use delay/force directly, but I don't think they compose well with stream-*
<wklew>stream-let would be the closest to what I have now, where I build a tree using a named let
<wklew>so that's cool
<wklew>I'm actually doing a sort of append-map, where the value of each element is computed from its children
<wklew>interestingly there is no stream-append-map in SRFI-41
<leoprikler>a stream is basically a list, that may be infinite
<leoprikler>so append-map does not really make sense
<leoprikler>append-map only makes sense if its arguments are finite as otherwise there's nothing to concatenate