Language Guide: Page 3
A crash course in the particular workings of microscheme
Primitive Procedures
Primitive procedures are procedures that are built-in to the language. This means that the compiler produces efficient low-level routines for them.
Unlike full-blown Scheme, microscheme primitives are not first-class. i.e., they can only appear in the function application form. This is a problem when you want to pass a primitive function as the argument to a higher-order function such as map. For example, you may want to invert a list of Booleans: (map not list_of_booleans)
.
The solution is to make a simple wrapper-function which is first-class but performs the same function as the primitive you want to work with: (define (not* x) (not x))
.
Then, you are free to use it as a value: (map not* list_of_booleans)
. This might seem annoying, but it is not without good reason. Making all primitive functions first-class would tie up around .5 KB of RAM. On the arduino, RAM is precious. This compromise ammounts to you, the programmer, telling the compiler exactly which primitives need to be loaded into RAM. For the vast majority of programs, this ammounts to a massive memory saving.
Available Primitives
The primitive procedures built-in to compiler version 0.6 are:
- =, >, >=, <, <=, not
- +, -, *, div, mod, zero?
- number?, pair?, vector?, procedure?, char?, boolean?, null?
- cons, car, cdr, set-car!, set-cdr!
- list, vector
- vector-length, vector-ref, vector-set!
- assert, error
- include, stacksize, heapsize, pause
- serial-send, digital-state, set-digital-state