Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Binary Comprehensions

“The ships hung in the sky in much the same way that bricks don’t.” — Douglas Adams

Binary comprehensions hang in the syntax of LFE in much the same way that list comprehensions do—which is to say, elegantly and with a certain mathematical inevitability that makes one wonder why all languages don’t have them.

If you’ve grasped list comprehensions (and if you haven’t, may I suggest returning to that section before proceeding, as the concepts build upon each other rather like a Jenga tower, except more stable), then binary comprehensions should slot neatly into your mental model. They are, essentially, list comprehensions that produce binaries instead of lists.

Where list comprehensions transform lists into other lists, binary comprehensions transform:

  • Binaries into lists
  • Lists into binaries
  • Binaries into other binaries

This versatility is rather like having a Swiss Army knife, except that each blade is perfectly suited for cutting bits and bytes rather than wilderness survival tasks.