Saturday, July 19, 2003

Macro Examples

I realized that I didn't show how to use my macros in the earlier post. For the arithmetic if, I have a couple of examples:
(arith-if test-val

This evaluates to the string "negative", "zero", or "positive", depending on the value of test-val.
(arith-if test-val

(set! accum (- accum 1))
(set! accum 0)
(set! accum (+ accum 1)))
If test-val is negative, the accum variable is decremented, and if it is positive, accum is incremented. If test-val is zero, accum is reset to zero.
(p-for i 1 10 (display i)(newline))
This prints the numbers 1 through 10. It's that easy!

No comments: