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.
(match value & expr), where there are an even number of
valuemay be any Clojure value, including function calls. It is simply copied into the expanded code.
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:
pos?-- in this case, the test should apply the function to the value, as
fis a function with
(function? f),but first you have to
(ns user (:use clojure.test)).
(> 0)-- in this case, the value should be inserted as the second element, as
(> value 0).
:else, which in a
condis equivalent to
matchexpression can be translated into a
condexpression in a pretty straightforward way:
|For example,||Should expand to:|
matchmacro, and using it in two or three examples.
readme.txt, describing how to use your macro, and giving an example use and an example macro expansion.