Next: , Previous: , Up: The language   [Contents][Index]


5.17 Compiled Lisp

Librep contains a Lisp compiler as well as an interpreter; this takes a Lisp form or program and compiles it into a byte-code object. This byte-code object is a string of characters representing virtual machine instructions, a vector of constants and some other meta-information. The system also contains a byte-code interpreter; this takes the compiled byte-codes and executes them by simulating the virtual machine. This simulation will have exactly the same effect as interpreting the original form or program.

One of the main reasons for compiling programs is to increase their efficiency. Compiled functions are likely to be more efficient than interpreted counterparts in all areas (space and time). For example:

user> (define (fib n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
user> ,time (fib 30)
832040
Elapsed: 17.05572 seconds
user> ,compile
user> ,time (fib 30)
832040
Elapsed: 1.479007 seconds

—the compiled function is over an order of magnitude faster than the interpreted version.