I think this is an artifact of the type checker. It will run on a single file before any of the lines in the file are run. So, if you're trying to use a class that's only being imported with a Machine.add declaration, that declaration is not going to run before the type checker gets to the line where you use it. But, if a file has two Machine.add declarations, then the type isn't used in that file, so the type checker doesn't complain, then at runtime the first .add is run, followed by the second.

I guess a Machine.import would need to compile and run the file during compile time, which might be non-trivial because I'm not sure that the compiler can be gracefully interrupted. Maybe the "import" keyword is the way to go. This might be straightforward to do by adding a few rules to the grammar and making import be a reserved word, and allow a number of import statements (only?) at the top of of a program.

I have definitely faced the same issue when I was working on utility classes.

~Jack

On Sat, Aug 8, 2020 at 11:46 AM Curtis Ullerich <curtullerich@gmail.com> wrote:
Thanks for confirming. I subscribed to the issue in case it gains traction.

I found it curious that Machine.add used in the header of control.ck doesn't work, but it works if the libs and control.ck are Machine.added in the same file. Why is that?


On Sat, Aug 8, 2020, 11:35 Michael Heuer <heuermh@gmail.com> wrote:
Hello Curtis,

In LiCK there is one big import.ck file (your second method)


I typically use it with two terminal windows, in one

$ chuck --loop

and in the other

$ chuck + import.ck
$ chuck + other-stuff.ck

See also

Add namespaces and import statements

Cheers,

   michael


On Aug 8, 2020, at 12:56 PM, Curtis Ullerich <curtullerich@gmail.com> wrote:

What's the state of the art for imports/includes?

If I have files lib0.ck and lib1.ck that declare public classes both used in control.ck, I understand these to be the two options for running them:


or, make another file control-main.ck:
Machine.add("lib0.ck");
Machine.add("lib1.ck");
Machine.add("control.ck");

and run it as:

I thought it would work to use Machine.add("lib0.ck"); Machine.add("lib1.ck"); as the first line of control.ck and then just run chuck control.ck, but the included classes are not found. 

Are these the two options, or is there another way that can support transitive inclusion (not having to list each util file for every program that uses them)?

Thanks,
Curtis
_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users