Message Boards Message Boards

Lazy lists in Mathematica

POSTED BY: Sjoerd Smit
7 Replies

See also Chapter 6 on Computations with Infinite Structures in The Mathematica Programmer by Roman Maeder.

POSTED BY: Paul Abbott

Lazy evaluation is quite handy in optimising interactive code like Manipulate when you don't want to compute a whole set of data anew prior to the start of Manipulate or at every "refresh".

enter image description here - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!

POSTED BY: EDITORIAL BOARD

To be fair, I don't have immediate practical uses myself either, but they seem useful enough to have as a tool when the time comes. I imagine this can be useful to traverse large data sets. For example, you can represent a large file as a line-by-line lazyList, making it possible to map functions over it without having to read the whole thing into memory. You could to the same thing with databases.

POSTED BY: Sjoerd Smit

I would foresee lazuTuples as something that would be usefulÂ… Say you want to traverse a large number of tuples but do not want to create them all at startup because of memory.

POSTED BY: Sander Huisman

Good suggestion about Tuples. I added a lazyTuples function on my development branch, though it's probably not in its final form yet.

I based the methodology of off the SE answer below. It's well worth a read if you ever want to work with large numbers of tuples: https://mathematica.stackexchange.com/a/153609/43522

Edit I think I did everything I for the implementation of lazyTuples right now. In the future I may try to implement a feature to generate tuples in chunks rather than 1-by-1, but the current code should already work quite well.

POSTED BY: Sjoerd Smit

Neat! I do not immediately foresee practical uses myself, but I can imagine there are. Do you have any?

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract