Can't Split by Letter


I've notices long lengths of text don't work well on SPLIT.

it's not really a bug with snap, it's just splitting it by letter would use up too much memory. And it's not just with split by, the error can show up in any block that reports a list, such as numbers from

Is there a way to split by letter fast without erroring?

well, don't use split by letter on samples of sound converted to json. Sounds are super large, so of course the output would be too large for snap.

invalid array length:

new Array("foo bar baz")->rangeerror
new Array(-1)->rangeerror
new Array(Number.MAX_SAFE_INTEGER+1)->rangeerror

I don't know about fast, but you can do it using streams, and you won't run out of memory if you refrain from keeping a pointer to the head of the stream.

I've never heard of the term "streams" (in coding of course). What are they?

Ah, you should check out the streams library, and also read SICP 3.5.

Abstractly, a stream is a list, supporting operations ITEM 1 OF, ALL BUT FIRST OF, and IN FRONT OF, as well as the usual higher order functions. But how it's implemented is a list combining the first item with a promise to compute the rest of the list later.

When you cash in the promise (by calling ALL BUT FIRST OF), you get another stream -- one item plus another promise. If you keep butfirsting, and (important!) you refrain from keeping a pointer to the original head of the stream, the stream can effectively be infinitely long. In the library is a sample script that computes the stream of all the prime numbers.