[Prev][Next][Index][Thread]
Re: A basic question: defining modules and libraries
-
To: info-dylan@ai.mit.edu
-
Subject: Re: A basic question: defining modules and libraries
-
From: James <james@openscript.com>
-
Date: Thu, 23 Mar 2000 18:00:02 -0500 (EST)
-
Organization: The University of Chicago
-
References: <87u2hxct70.fsf@ethereal.dyndns.org>
-
Xref: traf.lcs.mit.edu comp.lang.dylan:11703
Hi Nolan,
I'll try to field this one. Basically, Dylan provides Libraries
and Modules as a way of managing namespace. Your code goes inside
of modules and those modules are a part of a library. You can choose
which parts of your code are exported from your module and which
modules are exported from your library.
As a programmer, you define which libraries you are going to use
as a part of your application and then from those libraries you pick
the modules that hold the code you are looking for. In the case
below, the make-dylan-app defines a library called 'myapp' that
includes the dylan library and the format-out library. It then
defines a module also called 'myapp' to hold your code. Before you
can do much of anything you need to include the dylan module in your
module to have access to the dylan environment. That is why all module
definitions include the use dylan; line at the beginning. You are
importing the dylan module from the dylan library. Similarly, you
need to have access the the main function for your app to work so you
need to import the extensions module, also from the dylan library.
To be honest, this caused me a lot of confusion too because there
are usually redundant names for libraries and modules and it can be
difficult to tell what is what. So I will try to explain based on the
format-out library.
There is a method called format-out which simply outputs to
*standard-out*. This method is written inside of a module called
'format-out' and this module is inside of a libarary called 'format-
out'. The names for the method, the module, and the libary could all
be changed, but what is important is that if I want access to the
method format-out inside my module, I need to import the
format-out module with
use format-out;
inside my module's definition. And beofre I can access the format-out
module, I need to import the format-out library with
use format-out;
inside my libary's definition.
This all seems like a lot of work for simple applications, which is
why there is a make-dylan-app utility, but it is really nice for larger
projects where you may want to define several modules to hold different
parts of your application. If you want to use ODBC, you can just grab an
ODBC library even from an outside source, and then import the ODBC
module
to have access to those methods. The trouble could be that one of the
methods or objects defined in the ODBC module could conflict with one of
your, but the great thing is that you can define how the ODBC module is
imported and resolve any name conflicts when your import the module
without having to re-write your code.
When you see this in action you realize that it is actually quite
nice. Saves a lot of time and makes re-using code a snap.
James
Nolan Darilek wrote:
>
> In an attempt to delve deeper into Dylan, I began studying the output
> of make-dylan-app. Here is a sample from myapp-exports.dylan:
>
> module: dylan-user
>
> define library myapp
> use dylan;
> use format-out;
> //use streams;
> //use standard-io;
> //use format;
> end library;
>
> define module myapp
> use dylan;
> use extensions;
> use format-out;
> //use streams;
> //use standard-io;
> //use format;
> end module;
>
> I think I understand the relationship between libraries and modules,
> but why is 'use dylan;' specified in both sections? I'm trying to
> grasp the significance of the various 'use' statements, and why some
> are placed within the library sections and others are placed alongside
> the module definition.
Follow-Ups: