CIS 554 Clojure Macro (for loop)
Fall 2014, David Matuszek

Purpose of this assignment

General idea of the assignment

Macros let you "extend the language," and are widely considered (by Lisp enthusiasts) to be what makes Lisp so great. So this assignment is about extending Clojure with macros. The question I had to solve was, what extension or extensions to make?

The most useful extensions are "large" ones. Provide code to support expert systems, like Clips or Jess. Provide pattern matching and backtracking, like Prolog. Build a sane GUI API, like REBOL/View or Ruby Shoes. There isn't that much that's really useful for small programs.

So: Implement while loops? Already been done, available on the Web. Besides, Clojure already has while loops (really--check the documentation). Well, how about list comprehensions? That's useful, and just a combination of filter and map. Oh, already been done. Besides, Clojure already has list comprehensions.

So everything is either too big a project, or already done. What does that leave? Something totally useless, of course. And what could be more useless in Clojure than a C-style for loop?

Well, that's been done, too. frowny face Amazing. But at this point I'm out of ideas for the "right size" macro, so a for loop it is.

Details

Implement a C-style for loop in Clojure, using macros. Call it for-loop.

C's for loops are more complex than most people realize or ever use, so we'll just go with the basic functionality that everyone knows. A for loop:

Use all of: defmacro, loop, template, quote and unquote.

Suggested reading

What to turn in

Turn in

Due date

Turn your assignment in to Canvas before 6am Wednesday, October 29.