Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!dont-send-mail-to-path-lines From: gyro@cymbal.reasoning.COM (Scott Layson Burson) Newsgroups: comp.lang.scheme Subject: modularization & large scheme programs Message-ID: <9103042308.AA13132@cymbal.reasoning.com.> Date: 4 Mar 91 23:08:43 GMT References: <5242@umbc3.UMBC.EDU> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: Gyro@reasoning.com Organization: The Internet Lines: 46 Date: 3 Mar 91 20:28:48 GMT From: "Alex S. Crain" 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. A simple solution is to prepend a "package prefix" to each of your global symbols. The disadvantage of this approach vis-a-vis CL packages is that you must always include the "package prefix" when naming a symbol; there is no concept of a "current package" in the context of which the prefix may be omitted from symbols in that package. That may sound distasteful, but I have used this approach in Lisps without packages and found it workable. If you really want objects that behave like instances, here is an approach I have used in CL without CLOS: ;;; Do we have DEFSTRUCT in Scheme? Anyhow, you get the idea. (defstruct window ;; The slots are the operations, not the instance variables. expose move reshape ...) (define (create-window left bottom width height ...) (let (... other instance variables ...) (letrec ((expose (lambda () ...)) (move (lambda (new-left new-bottom) ...)) ... other operations ...) ;; Now we build an instance of the WINDOW structure using EXPOSE etc. (make-window expose move reshape ...)))) Here the instance variables are the arguments to CREATE-WINDOW along with any local variables bound in the LET. As you see, they are not accessible to the outside except by way of the operations you define. Now to invoke the MOVE operation on WIN: ((window-move win) x y) Note that this uses closures, but not continuations. -- Scott