Tue Aug 19 15:27:29 CEST 2008
Two kinds of parameterized code
1. Quoted macros are (compile time) values in Coma, so they can be
used to parameterize other macros.
2. It is possible to use Scheme's macro mechanism and the ``parsing
words'' extension built on top of it.
Which one should you use?
These two are somewhat complementary. The former is cleaner, since it
works on the code transformation level. The latter is specifically
designed to introduce names and is _just_ source syntax manipulation,
but can be useful for abbreviations.
An example of the first approach: waiting for a startbit, which is a
high->low transition on a pin.
: wait | q-cond? |
q-cond? i if begin q-cond? i not until then
begin q-cond? i until ;
: startbit? PORTC 0 low? ;
: wait-start ' startbit? wait ;
Parameterization here is accomplished by passing the quoted macro
"startbit?" to another macro "wait" that will instantiate (interpret)
the macro. Instantiation/interpretation uses the short Joy-inspired
Shorter, with anonymous quotations enabled:
: wait-start [ PORTC 0 low? ] wait ;