[Prev][Next][Index][Thread]
Dylan source in one file?
-
To: info-dylan@ai.mit.edu
-
Subject: Dylan source in one file?
-
From: Hugh Greene <q@tardis.ed.ac.uk>
-
Date: Thu, 13 Jul 2000 12:00:02 -0400 (EDT)
-
Organization: Division of Informatics, The University of Edinburgh
-
Xref: traf.lcs.mit.edu comp.lang.dylan:12454
Just an idle thought I had yesterday ...
One of the little niggles for Dylan beginners is that, for existing
implementations using Dylan Interchange Format (DIF) files at least, every
dylan program needs at least two source files. One looks like
Module: dylan-user
define library foo ... end;
define module foo ... end;
and the other like
Module: foo
// Main definitions here
I suppose there's no reason why you couldn't define lots of things in
dylan-user, so that might do for trivial examples. But you can't import
any other modules than dylan nor export things from it (because you can't
write its module definition) so for non-trivial examples, you're still
stuck.
Now, reading the DRM definitions of the DIF and the way modules and
libraries work, it seems the following needn't be illegal, though it might
be tricky to implement. All in one file:
Module: foo
define library foo ... end;
define module foo ... end;
// Main definitions here
You can think of the "Module: foo" as a forward reference, which has to be
checked when you get to the module definition. Now, technically, you
can't parse the library and module definition macro calls until you know
that they're in a module which uses dylan (or otherwise provides similar
macro definitions). So I'm wondering whether it would be feasible and
acceptable to implement this "forward reference" by *assuming* that the
standard dylan library and module definitions are imported from somewhere,
and checking that when you've processed the library and module
definitions.
Tricky cases might include:
- The macros are imported indirectly from the dylan library/module,
e.g., via common-dylan.
- There are macros defined/imported which accept the syntax of the
standard library and module defining macros, but expand to something
different. (This should still be okay, as long as the right module
gets defined at some point in the macro expansion!) Note that you
don't need to define anything to import or call macros (minimalist
obfuscated Dylan, anyone? :->).
And on top of all that, it introduces the possibilities of
- Breaking the flexibility of top-level definition ordering (because we
can't parse any other definitions, or at least not any other than
those in the dylan module, until we've sorted out the "real" module
definitions.
- Breaking backward-compatibility with existing implementations (unless
this all already magically works -- I haven't tested it ;-)
- Confusing users as a consequence of the above ... especially the new
users this idea is intended to help!
- Leading users into the habit of not having a separate file for library
and module definitions. I'm not *sure* this would be a bad thing but,
at least in FunDev, the analogue of C's conditional compilation is
usually done by having separate projects sharing partially overlapping
sets of source files. This tends to be needed for scaling to
larger projects and having library and module definitions in the same
files as other definitions would make this solution less obvious. But
maybe some "advanced tutorial" documentation could explain this
"evolution" ... or maybe we'll come up with a better solution for
conditional compilation :-)
Comments? Flames? ;-)
Hugh
Follow-Ups: