Eager Comprehensions in Scheme The design of SRFI 42
Sebastian Egner · 2005
This article is about a certain style of programming iterati ve programs. It is based on a concept we have named “eager comprehension,” which is a convenient and efficient alternative to tail recursion, do-loops, and lazy list comprehensions (aka “ZF expressions”). Eager comprehensions are syntactic forms that encapsulate the details of an accumulation process (counting elements, creating a list, etc.). Within these forms, expressions called gener ators hide the details of enumerating basic sequences (running through a list, through a range of integers, etc.). By combining these elements in a clearly structured and well-defined way, a concise and powe rful notation for writing loops emerges. Of course, this style of programming is not new—it is implicitly present in any form of loop-macro already—and so we discuss several concrete designs that aim for the same goal. Surprisingly, however, none of these designs has had much impact on Scheme, despite the fact that their common floor plan has been around f or decades. A particularly clean new design, SRFI 42, on the other hand has already made some friends in the first few years of its existence. Explaining the design and implementation of SRFI 42 constitutes the main part of this article.