[chuck-users] Is there plans for something like "include"

Ge Wang gewang at CS.Princeton.EDU
Thu Jan 5 14:21:22 EST 2006


Hi Michael!

> I was wondering if there were plans to implement a method for
> "including" a file in another? Something on the order of C's include,
> or Java's import?

There are plans (and even some implementation) for a name-based automatic 
file look-up (similar to Java class resolution).  It is currently on hold 
to make way to implement other features.  We have yet to invent/purloin
a package-level include mechanism.  It (or another include/import method) 
will make its way into the language (in a few months hopefully).

> Basically, I have some objects, that I would like to work with accross
> several files. and rather than having to explicitly put the code into
> each file.

So far, there is the following (ghetto) method:

1. each .ck may contain one 'public' class (like java) - put important 
classes into their own .ck files (as 'public class').

2. 'running' such a .ck file will add the class to the type system, which 
subsequent code can instantiate.

For example:

   foo.ck : contains public class Foo definition
   bar.ck : cotnains public class Bar definition
   par.ck : uses Foo and Bar

as long as foo.ck and bar.ck gets compiled/run before par.ck, things 
should work:

   > chuck foo bar par

3. instead of running foo and bar on the command line every time, you can 
write one addition .ck file which runs the dependencies:

// run foo.ck bar.ck
machine.add( "foo.ck" );
machine.add( "bar.ck" );
// etc...

if you want, you can also add par.ck from this file so you end up running 
one .ck file.

4. caveats:
- currently, once a public class is added, it lives in the global 
namespace and can not be modified/removed.
- machine.add( ... ) happens explicitly at runtime and is different from 
a static include.  therefore putting machine.add( "foo.ck" ) at the top 
of a program (par.ck) that uses Foo does not work.

Again, this method is really ghetto, but we hope it helps.

Best,
Ge!


More information about the chuck-users mailing list