Open
Description
require "foo/bar/baz"
After i test it, it seem like the lookup path is: (assume CRYSTAL_PATH is lib)
lib/foo/bar/baz.cr
lib/foo/bar/baz/baz.cr
lib/foo/src/bar/baz.cr
But, i never saw any document mention it.
I consider this is a really important concept for the crystal user, but i understood it until now because there no document.
Before this, i have to use absolute path from the lib. e.g. require "foo/src/bar/baz"
Activity
straight-shoota commentedon Mar 17, 2023
Here you go: https://crystal-lang.org/reference/1.7/syntax_and_semantics/requiring_files.html#other-forms
I think that should be sufficient documentation?
zw963 commentedon Mar 18, 2023
Oops, sorry, i don't know why i missing it!
BTW: the explain in other-forms is not accurate, because
require "foo/bar/baz"
seem like never searchfoo/src/bar/baz/baz.cr
.require
lookup paths crystal-lang/crystal#13210straight-shoota commentedon Mar 21, 2023
Indeed that seems to be the case. I figure this might be an unintended omission. So we probably need to change the implementation, not the documentation.
I think this might've eventually been lost in crystal-lang/crystal#10820.
I created crystal-lang/crystal#13210 to address the issues with require paths.
zw963 commentedon Mar 22, 2023
Oops, i thought i see it before, but i lose completely now for how
require
search file.Let us not think about our implementation(it probably wrong, right?)
What is the expected search path for following requires? (for lib only)
I remember when i first use Crystal (1.4), i read document somewhere said
require "foo"
will searchlib/foo/src/foo/foo.cr
, i even try it, it works. but, obviously, it not work anymore now for 1.7.2.straight-shoota commentedon Mar 22, 2023
No,
lib/foo/src/foo/foo.cr
was ever looked up, neither in Crystal 1.0 nor 1.4. I checked that.