[plt-scheme] Am I being required or...?

From: Synx (plt at synx.us.to)
Date: Sun Mar 28 04:02:34 EDT 2010

How would I test if the current module being run has been required from
another module, or was directly executed by mzscheme, mred or drscheme?
For instance (require "some-module.ss") and ($ mzscheme some-module.ss)
would both load the module, so if I had an example program running with
($ mzscheme some-module.ss) it would also run for every other program
that required the darn thing.

I've resorted to various hacks in the past such as making a
do-example-for-some-module.ss file (and trying to remember to update it
along with some-module.ss), or providing a "main" procedure for the -m
switch (which requires tons of (except-in) require clauses). But is
there a way to definitively /do/ it, that is have a program in a module
conditionally execute certain code depending if that module has been
required via (require) or it has been run from scratch as the file?

Posted on the users mailing list.