[plt-scheme] Modules, structs and environments

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Nov 19 11:32:32 EST 2007

In this case, I would start a read-eval-print-loop, feed the "struct.ss" 
to it (i.e. the reader), and then continue with what ever you want to do.

Chongkai

Joel J. Adamson wrote:
> The following message is a courtesy copy of an article
> that has been posted to comp.lang.scheme as well.
>
> Howdy Schemers,
>
> There's something I'm not getting about require'ing modules,
> environments and how to export struct definitions.  I'm using PLT Scheme
> (MzScheme only) 371.  When I import a struct and then start a new REPL,
> I get undefined identifier from within the REPL for make-`struct'.
>
> Here's some test code:
>
> ;;;;;;;;;;;;;;;;;;;;
> ;; struct.ss
> ;; this is a library that creates the struct and exports
> ;; it.  
> (module struct mzscheme
>   (provide (struct test-struct (f1 f2)))
>   (define-struct test-struct (f1 f2)))
>
> ;; run.ss
> ;; This is "main"
> ;; I compile this with `mzc -v --exe run run.ss' and then invoke it from
> ;; the command-line
> (module run mzscheme
>   (require "struct.ss")
>
>   (define test (make-test-struct
>                 'apple
>                 'banana))
>
>   (display test)
>
>   (read-eval-print-loop))
> ;;;;;;;;;;;;;;;;;;;;
>
> This prints "<struct:test-struct>" (i.e., it works) and then enters the
> REPL.  If I `make-test-struct' in the REPL I get "undefined identifier:
> make-test-struct"
>
> The obvious explanation is that the REPL initializes the namespace and
> therefore the struct is not imported into the new namespace.  In that
> case, should I pass the environment to the REPL, and how would I do
> that?  I started defining my own `eval', which seems like either playing
> with fire or a sign of a novice ;)
>
> Also I read in a draft of R6RS that run-time identifiers must be
> imported with some qualification or flag --- do I need to do that in
> mzscheme?  If so, how?  All I've found is require-for-syntax and
> require-for-template: is there a require-for-run?
>
> The overall rationale: my real program is to take an input file
> (currently composed of scheme code) and evaluate it, and print the
> results to an output file or STDOUT.  After I configure the input and
> output ports from command line options, starting an REPL seemed to be
> the easiest way to do this.  If there's a better way, please let me
> know.  I will add custom printers and all that, but that is pretty far
> down the road.
>
> Thanks,
> Joel
>   



Posted on the users mailing list.