For Programmers: Free Programming Magazines  


Home > Archive > Scheme > June 2004 > load









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author load
nobody

2004-05-23, 11:37 am

Hello!

I am trying to do the following:

The test.scm (the main program) should read a configuration file config.scm
(another scheme file). The configuration parameters are simple define
statements in the config.scm. At the end the test.scm will be "compiled" by
mzc into the .exe file but the resulting .exe file should load the
config.scm at runtime (using load-relative).

Now, the load works if the test.scm does not contain the module declaration.
If it does I get the "unbound variable output-file" error. The module
declaration is needed for mzc to produce the executable :-(. Is there a
simple way out of this?

The code in test.scm is:

(module test mzscheme
(load-relative "config.scm")
(display output-file)
)

The code in config.scm is:

(define output-file "c:\\tmp\\output.pdf")




David Van Horn

2004-05-23, 1:37 pm

nobody wrote:
> Hello!
>
> I am trying to do the following:
>
> The test.scm (the main program) should read a configuration file config.scm
> (another scheme file). The configuration parameters are simple define
> statements in the config.scm. At the end the test.scm will be "compiled" by
> mzc into the .exe file but the resulting .exe file should load the
> config.scm at runtime (using load-relative).
>
> Now, the load works if the test.scm does not contain the module declaration.
> If it does I get the "unbound variable output-file" error. The module
> declaration is needed for mzc to produce the executable :-(. Is there a
> simple way out of this?
>
> The code in test.scm is:
>
> (module test mzscheme
> (load-relative "config.scm")
> (display output-file)
> )
>
> The code in config.scm is:
>
> (define output-file "c:\\tmp\\output.pdf")


Here's one solution:

;; test.ss
(module test mzscheme
(provide (all-defined))
(define output-file (make-parameter #f))
(load-relative "config.scm")
(display (output-file) (newline)))

;; config.scm
(require "test.ss")
(output-file "c:\\tmp\\output.pdf")

> mzc --auto-dir test.ss
> mzscheme -u test.ss

c:\tmp\output.pdf

hth,
David

nobody

2004-05-24, 12:36 pm

Thank you for the code, I tried it and it works - even I do not fully
uderstand how ;-).
Why there is a need to import test.scm into the config.scm? It looks odd
that the module containing a configuration info would import every module
which uses _it_, the logical sequence is for test.scm import the config (not
vice versa).

"David Van Horn" <dvanhorn@cs.uvm.edu> wrote in message
news:c8qi8s$5ea$1@news.epidc.co.kr...
> nobody wrote:
config.scm[color=darkred]
by[color=darkred]
declaration.[color=darkred]
>
> Here's one solution:
>
> ;; test.ss
> (module test mzscheme
> (provide (all-defined))
> (define output-file (make-parameter #f))
> (load-relative "config.scm")
> (display (output-file) (newline)))
>
> ;; config.scm
> (require "test.ss")
> (output-file "c:\\tmp\\output.pdf")
>
> c:\tmp\output.pdf
>
> hth,
> David
>



David Van Horn

2004-05-24, 3:32 pm

nobody wrote:
> Thank you for the code, I tried it and it works - even I do not fully
> uderstand how ;-).
> Why there is a need to import test.scm into the config.scm? It looks odd
> that the module containing a configuration info would import every module
> which uses _it_, the logical sequence is for test.scm import the config (not
> vice versa).


That's easy enough to fix, just move the require form into the module (using
eval):

;; test.ss
(module test mzscheme
(provide (all-defined))
(define output-file (make-parameter #f))

(eval '(require "test.ss"))
(load-relative "config.scm")

(display (output-file))
(newline))

;; config.scm
(output-file "c:\\tmp\\output.pdf")

David
nobody

2004-06-03, 7:27 pm

Thank you for your help...

"David Van Horn" <dvanhorn@cs.uvm.edu> wrote in message
news:c8tgjq$3hf23$1@swen.emba.uvm.edu...
> nobody wrote:
module[color=darkred]
(not[color=darkred]
>
> That's easy enough to fix, just move the require form into the module

(using
> eval):
>
> ;; test.ss
> (module test mzscheme
> (provide (all-defined))
> (define output-file (make-parameter #f))
>
> (eval '(require "test.ss"))
> (load-relative "config.scm")
>
> (display (output-file))
> (newline))
>
> ;; config.scm
> (output-file "c:\\tmp\\output.pdf")
>
> David



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com