Vadim Zaytsev aka @grammarware

DYOL: Design Your Own LanguageComprehension


Caveat emptor: these individual card pages are work in progress, and their content is in no way final!

Comprehension

List and set comprehensions are language constructs resembling the mathematical notation for creating a set by its characteristic function ("for all numbers from 1 to 10, give me their squared values"), and combine map and filter classical for functional programming. Comprehensions as a language construct exist in Haskell, Python, Rascal, C# and some other languages.

Examples

Produce a list of squares of numbers from 1 to 10 inclusively

Haskell
[x*x | x <- [1..10]]
Rascal
[x*x | x <- [1..11]]
Python
[x*x for x in range(0,11)]
C#
Enumerable.Range(1, 11).Select(x => x*x)

The DYOL toolkit was created and is maintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Page last updated in March 2021.
XHTML 1.1 CSS 3