Next: , Previous: , Up: Modules   [Contents][Index]

5.12.3 Simple Module Definition

In its simplest form, a module definition looks like this:

(define-structure simple.test
    (export foo
    (open rep  ;; Make it rule to open `rep' always.
  (define (foo x) (* x 42))
  (define (bar x) (baz x (foo x))
  (define (baz x y) (+ (foo x) (1+ y)))
  (format standard-error "Module %s defined!" (current-structure))

This module has the name simple.test. Then it “exports” two bindings, foo and bar, functions in this case. It also declare to use modules rep and rep.structures. The entire order is fixed; first export, then open, and the rest.

Always make it rule to open rep structure. It’s because Librep used to offer alternative Lisps, for example Scheme mimicry by importing scheme structure, instead of rep module.

Then comes the body. They’re evaluated when define-structure is evaluated, inside of this module. It defines three functions, and it emits a message to stderr. The third function baz is not exported, so it can’t be seen outside of this module.

The function current-structure is defined in rep.structures, and it can be used in this module because rep.structures was opened.

Wrong open and export

Suppose a module declares to open a non-existing module. It signals an error at evaluation as it should be. But byte-compilation can be done, without any error or messeage. Sorry.

A module can export a symbol which is not bound in that module. Sorry.