A simplified view of the problem I am trying to sort out:
Say I have written a little library, perhaps of various maths utilities.
There are several files all providing different features. I make them
available to the user by 'requiring' them and 'providing' them all from the
top-level main.rkt file.
No problems there. I have also made this an installable #lang, lets's call
it '#lang rat' (for rational, of course) by adding the line
(module reader syntax/module-reader rat)
to the top of the main.rkt file, and also
(provide (all-defined-out) #%module-begin #%app #%datum #%top-interaction)
So far so good.
Now, say I want some of the modules to have special treatment. For
instance, say I don't want the polynomials module to be available
straightaway when "#lang rat" is fired up, but I want the user to have to
(require rat/polynomial) [but to be free of having to specify the
file-path, which may be intricate]. Only the name should be necessary. If
I've understood correctly, my polynomials.rkt file will have to be made a
module (or a submodule). So I go to that file and instead of #lang racket,
at the top, I put
(module polynomial racket
;; these are all the various polynomial modules:
(require "pcf.rkt" "fpf.rkt" "rcf.rkt" "pcf-fpf.rkt")
(provide (all-from-out "pcf.rkt" "fpf.rkt" "rcf.rkt" "pcf-fpf.rkt")
; do I need more here? perhaps any of these...
; #%module-begin #%app #%datum #%top-interaction
)
)
This does not seem to help much.
Furthermore, this is going to become even more important to me soon, as I
have cases where I have to 'eval' expressions expressions inside syntax,
and that syntax is not in the same file as my evaluation environment. I
know that if I have the handle of the module I can do (module->namespace
'polynomial) and then use that namespace as the second parameter to eval,
but how do I get the module handle in the first place?
The example given in the docs:
> (module m racket/base
(define x 11))
> (require 'm)
> (define ns (module->namespace ''m))
> (eval 'x ns)
11
only works in file scope, but if I try to call the "polynomial" module from
another file, either say the main file, or elsewhere in the code, or even
in the DrRacket definitions, or the REPL 'polynomial or 'rat/polynomial is
not recognised (not that I really expected it would)
Trying to specify it by file name is just a disaster. So how do I define a
module (or submodule) in one of my files and have it accessible to the rest
of the program?
I have also read that modules and submodules can be nested, so I thought
perhaps this was the cause of its failin -, it should should be nested in
my main.rkt file - but as I said, my module line in main.rkt is merely
(module reader syntax/module-reader rat), and all the functionality of the
main file follows it, IOW it's not enclosed, in the (module ...) scope, as
that is occupied by the 'rat' keyword.
Any hints suggestion tips corrections pointers most welcome, I am off to
read the documents once again, but it's a bit of a rough slog. A simple
tutorial explaining this stuff by example would be most welcome.
The thing is, as I have occasionally mentioned, I am porting old Scheme
code and as you know, r5rs does not really support modules, so between them
MIT-Scheme, Guile, and Chez come up with some really imaginative and wild
ideas to compensate for this. Environments (the equivalent of modules) get
augmented and switched - sometimes haphazardly - and trying to muster it
all into correct Racket is certainly an educational endeavour...
My apologies for not including actual code. I have some stuff ready to go
up on github, but frankly it's still a bit too messy to made public imho.
I'd like to get some of the basic-basics sorted out first. If needs
absolutely must, I will, but I think (that for now at least) I can still
express the problem clearly enough to be understood in words.
TIA
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.