CIS 554 Clojure Macro
Fall 2015 David Matuszek

Purpose of this assignment

General idea of the assignment

A macro definition is very similar to a function definition. However, when a function is called, it returns a value; when a macro is called, it returns code, which is then executed. Macros let you "extend the language," and are widely considered (by Lisp enthusiasts) to be what makes Lisp so great.


Define a macro (match value & expr), where there are an even number of expressions.

The value may be any Clojure value, including function calls. It is simply copied into the expanded code.

Each pair of expressions consists of (1) a test applied to the value, and (2) an expression to be evaluated and returned if the test passes. Each test may be:
A match expression can be translated into a cond expression in a pretty straightforward way:

For example, Should expand to:
    (match v
7 "lucky number"
pos? "positive"
(< 0) "negative"
:else "zero" )
(= v 7) "lucky number"
(pos? v) "positive"
(< v 0) "negative"
:else "zero" )

Suggested reading

What to turn in

Turn in

Due date

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