File: package

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (42 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
S9 LIB  (package <name> <option> ... <body>)  ==>  unspecific

PACKAGE packages the definitions in its <body> in such a
way that they are not visible outside of its body, i.e.
the scope of each definition is the <body> of the package.
There must be at least one definition in <body>.

There may be any number of <option>s preceding the definitions
in the <body> of PACKAGE. All options are lists with a symbol
beginning with a #\: in their first positions. The following
options exist:

(:EXPORT symbol ...) lists the symbols to exported from the
package. When the name X of a definition occurs in :EXPORTS, a
symbol with the name <name>:X will be made visible outside of
the package. That symbol will be bound to the same value as X
inside of the package.

(:IMPORT symbol ...) lists the symbols to imported into the
package. A symbol that is being imported into a package may be
redefined later outside of the package without affecting its
binding inside of the package.

(:MAKE-ALIASES) will create an alias named X for each exported
symbol named <name>:X, i.e. it will allow to refer to an object
defined in a package by the same name inside and outside of the
package.

(package bar
  (:export foo2 foo3)
  (:make-aliases)
  (define (foo-maker n x)
    (if (zero? n)
        (lambda ()
          x)
        (foo-maker
          (- n 1)
          (cons n x))))
  (define foo2 (foo-maker 2 '()))
  (define foo3 (foo-maker 3 '())))

(list (bar:foo2) (foo3))          ==>  ((1 2) (1 2 3))