[comp.lang.scheme] modularization of scheme code

alex@umbc4.umbc.edu (Alex S. Crain) (03/04/91)

	I'm laying out a rather large project (an operation system) in
scheme and I'm looking for a way to restrict the scope of some objects.
In C++ or CLOS, I would use objects and methods, in vinnilla CL I would
use packages. I can't find a good way to do this in scheme.

	For example: suppose I was writing window system, and I had written
a module for screen management. I would have some local data objects
(like the screen data and backing store data (after securing the appropriate
patent licence from AT&T, of course). I would also have some local functions
and finally, I would have some exported functionality (create-window, etc).

	I would rather not make my locally used functions and data structures
public if I don't have to, both to avoid cluttering the namespace and just
for general neatness. Scheme doesn't provide a way (that I know of) of
hiding anything except by nesting itside a function, and even if I
wrapped the entire module inside of letrec body I don't know how to make
the date structures permentent, and I only get one entry point (yuk).

	Or should I build everything dynamically and export a series of
continuations to use as entry points, ala:

(define (init-screen non-local-exit)
  (letrec ((screen-data (make-vector ...))
	   (entry-points '(()))
	   ...
	   )
    ;;
    ;; define the new entry points
    ;;
    (let ((x (call/cc (lambda (k) (cons 'init k)))))
      (case (car x)
	((init) (set-car! entry-points (cdr x)))
	((create-window) ...)
	((delete-window) ...)
	...))

    (non-local-exit entry-points)))
	
	
(define (go)
  (let ((screen-calls (call/cc (lambda (k) (init-screen k)))))

    ...
    
    (screen-calls 'create-window)

    ...

    (screen-calls 'delete-window)))



So, pray tell, whats to scoop? I'm working out of R3.99rs, so if this is
crystal clear in 4.0, just say so.
#################################		           :alex.
#Disclaimer: Anyone who agrees  #                 Systems Programmer
#with me deserves what they get.#    University of Maryland Baltimore County
#################################	    alex@umbc3.umbc.edu

markf@zurich.ai.mit.edu (Mark Friedman) (03/05/91)

In article <5241@umbc3.UMBC.EDU> alex@umbc4.umbc.edu (Alex S. Crain) writes:

     I would rather not make my locally used functions and data
   structures public if I don't have to, both to avoid cluttering the
   namespace and just for general neatness. Scheme doesn't provide a
   way (that I know of) of hiding anything except by nesting itside a
   function, and even if I wrapped the entire module inside of letrec
   body I don't know how to make the date structures permentent, and I
   only get one entry point (yuk).

Using your example try something like the following:

(define create-window #f)
(define delete-window #f)
(let ()
  (define screen-data (make-vector ...))
  (set! create-window
	(lambda ...))
  (set! delete-window
	(lambda ...)))

The assigned values of create-window and delete-window can access
screen-data with impunity whereas the user of those procedures has no
access to screen-data.

-Mark
--

Mark Friedman
MIT Artificial Intelligence Lab
545 Technology Sq.
Cambridge, Ma. 02139

markf@zurich.ai.mit.edu