[plt-scheme] Problem with compiled file dependencies

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Mar 19 04:30:02 EDT 2007

At Sat, 10 Mar 2007 15:19:42 +0000, "Paulo J. Matos" wrote:
> I've tried using mzc -k but even if I do use that to compile foo:
> ~/test $ mzc -k foo.scm
> mzc v369.8 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
> "foo.scm":
>   making "/home/pmatos/test/foo.scm"
>   making "/home/pmatos/test/bar.scm"
>  [output to "./compiled/foo.zo"]
> pmatos at euler ~/test $ cd compiled/
> pmatos at euler ~/test/compiled $ ls
> bar.dep  bar.zo  foo.dep  foo.zo
> Now I get to mzscheme:
> $ mzscheme
> Welcome to MzScheme v369.8 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
> > (dynamic-require "test/compiled/foo.zo" 'foo-test)
> default-load-handler: cannot open input file:
> "/home/pmatos/test/compiled/bar.scm" (No such file or directory;
> errno=2)

You should still use

  (dynamic-require "test/foo.scm" 'foo-test)

Since "compiled/foo.zo" exists relative to "foo.scm", and since it has
a newer date, "compiled/foo.zo" will get used instead of "foo.scm".

The idea is that you should be able to run from source, but that
running `mzc -k' should generate ".zo" files that are automatically
used in place of source files. The ".zo" files are even used if the
source file no longer exists, in case you want to distribute just ".zo"
files without source.

The automatic loading of ".zo" files can be a little confusing if you
don't use it in exactly the expected way. In particular,

  (dynamic-require "test/foo.zo" 'foo-test)


  (parameterize ([current-directory "test"])
    (dynamic-require "foo.zo" 'foo-test))


  (dynamic-require "test/foo.plt-scheme" 'foo-test)

also work --- again, because "compiled/foo.zo" exists relative to a
potential "foo.zo" or "foo.plt-scheme" *source* file, even though the
source file isn't actually there. The suffix for the source (".scm",
".zo", or ".plt-scheme") doesn't matter, and the fact that the source
file doesn't exist doesn't matter; a compiled file exists in the
expected place, and so it gets loaded.


  (dynamic-require "test/compiled/foo.zo" 'foo-test)

doesn't work, because "test/compiled/foo.zo" is treated as a source,
and it embeds a reference to "bar.scm" relative to the source. So
reference is to "test/compiled/bar.scm" (the source version) or
"test/compiled/compiled/bar.zo" (the compiled version), neither of
which exist.


Posted on the users mailing list.