You wrote:
-------------------------------------------------------------------------------
As Matthias mentions, you can formally link together "units" together.
Units are Racket's dependency-injection component framework.  You can
read documentation about them here:

   http://docs.racket-lang.org/guide/units.html

--------------------------------------------------------------------------------
Thanks for the pointer, but unfortunately, the docs as they are don't seem to provide a meaningful starting point for experimenting with the code, or I may be too daft to make sense of it (probably the latter). Here's what I did:

1. Copy-and-paste the four code fragments verbatim into four files named (as the docs suggested) toy-factory-sig.rkt, simple-factory-unit.rkt, toy-store-sig.rkt and toy-store-unit.rkt, respectively

2. Changed all require references to (require (file "f://testpath//toy-store-sig.rkt")) etc because I couldn't find any other
way for wither DrRacket or Racket to accept the paths

3. (as the docs suggested) typed (require (file "f://testpath//simple-factory-unit.rkt")) in DrRacket

DrRacket now responded with

..\..\install\racket\collects\syntax\modcode.rkt:46:8: load-handler: expected a `module' declaration for `simple-factory-unit' in #<path:f:\testpath\simple-factory-unit.rkt>, but found something else

looking through some older discussions, I discovered that the module headers seem to be mandatory to be able to work with units, but they are implicitly added when the language is set to racket/unit. I tried that on the top level in DrRacket but would get the same error. I then tried adding #lang racket/unit to all files but got this error:

f:\testpath\simple-factory-unit.rkt:1:0: #%module-begin: missing an `import' clause in: (#%module-begin (require (file "f://testpath//toy-factory-sig.rkt")) (define-unit simple-factory@ (import) (export toy-factory^) (printf "Factory started.\n") (define-struct toy (color) #:transparent) (define (build-toys n) (for/list ((i (in-range n))) (make-toy (quote blue)))) (define (repaint t col) (make-toy col))) (provide simple-factory@))

I would REALLY like to understand the concepts, but in order to do that, I need to have working code that I can play around with. Could anybody please provide a working instruction to get the code samples from the documentation to run so I have a starting point? That means either provide explicit module wrappers for the files or describe a way to set the language such that the code runs as is?

Thanks again to this really great and dedicated community!


____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to