Are you able to change the require order? Crystal 0.35.1

I’m using REPL.it, I would LOVE to use the latest version but I have to wait for them. Anyways… in short: I’ve made a class in one file, being able to use it everywhere else I put a require "./*", but now in another the require stops working – I get a compile error saying the class doesn’t exist. I don’t know what’s happening although I suspect it has something to do with require order and what’s available at one point to another. Trouble is, I tested out a smaller version of the same problem and it went away! So I’m very confused. Link if it’s relevant: https://repl.it/@Th3OneAndOnly/AwesomeHonorableParallelprocessing

The best solution here is to just not use that and require the files manually. Using a glob like that usually isn’t the best idea as you run into problems like this.

Another solution would ofc be to install Crystal locally and get the latest version :wink:.

I would if I could :frowning:. I’m a Windows User.

For the actual answer, I find that solution to be a bit tedious, but oh well. Thank you!

Install On Windows Subsystem for Linux - The Crystal Programming Language is always an option. Are quite a few people that use it and as far as I know it works quite well.

Also fwiw every file doesn’t need to require every other file. Normally you have a main file that requires all the children. Only times I noticed when a sub file needs an explicit require is if it uses a type defined before it. I.e. type a.cr uses a type defined in z.cr within some sub directory.

I was thinking of “tree” like structure file requiring. In my project, I’m replicating craftinginterpreters in Crystal so maybe I’d have lox.cr require scan.cr, parse.cr, and interpret.cr. Then those require both expr.cr, tokentype.cr, and, when I get there, stmt.cr. Or is there a more efficient method to which you were referring?

Right yea. Have run.cr require lox.cr. Then lox.cr require the files that it uses. Most of the time it’s a good idea if each file requires the stuff it uses that isn’t already included where that file was included.

I’m not sure if it’s correct but I’ve always assumed files are required in alphabetical order when using a glob require. So if you do require "./*" it will load a.cr before b.cr. If there’s a specific file that is being required later than you need it to with the glob, you can just add it above the glob to force it to be required first

require "./b"
require "./*"