[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A module question

John Ramsdell:
> In the Curtis/Rauen module proposal, what do non definitions within
> modules mean?  For example, what is printed by the following program?
> (interface a (value x))
> (interface b (value y))
> (module f ((exports a) (imports b) (open b))
>   (define x 0)
>   (set! x (+ x y)))
> (module g ((exports b) (imports a) (open a))
>   (define y 0)
>   (set! y (+ x y)))
> (display f#x)
> (display g#y)

First, modules are anonymous, and a reference to a shared item like
"f#x" above is made via the interface name.  So the above program
should actually be:

(interface a (value x))
(interface b (value y))
(module ((exports a) (imports b) (open b))
  (define x 0)
  (set! x (+ x y)))
(module ((exports b) (imports a) (open a))
  (define y 0)
  (set! y (+ x y)))
(display a#x)
(display b#y)

Expressions and definitions inside a module are evaluated in order, in
the order that the modules appear in the program.  Expressions in this
context are only useful for their side-effects.  In the example, the
first assignment statement would be in error, because it makes a
reference to "y" before y is defined.

Your example program is equivalent to the following plain Scheme

(let ((a_x #!UNSPECIFIED)	; Shared variables, initially unbound
      (b_y #!UNSPECIFIED))	;		.

  (let ()			; Translation of first module
    (set! a_x 0)		;		.
    (set! a_x (+ a_x b_y)))	;		.

  (let ()			; Translation of second module
    (set! b_y 0)		;		.
    (set! b_y (+ a_x b_y)))	;		.

  (display a_x)
  (display b_y))

By the way, I have been working on an implementation that translates
programs with modules into plain Scheme (like the translation above).
I'll send word out when it's ready.