Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init.q optional in one-file package #9

Open
danielkrizian opened this issue Dec 5, 2020 · 1 comment
Open

init.q optional in one-file package #9

danielkrizian opened this issue Dec 5, 2020 · 1 comment

Comments

@danielkrizian
Copy link

danielkrizian commented Dec 5, 2020

In a lean package with just a single file, there is no need for the boilerplate overhead of init.q. At least, init.q should be optional, not mandatory.

$ ls $QPATH/my-1.0.0
my.q
$ cat $QPATH/my-1.0.0/my.q
\d .my

This conditional statement:

file: $[not 11h ~ type key pkgInfo[`file];pkgInfo[`file];` sv pkgInfo[`file],`init.q];

will resolve to false even for single-file directory:

q) key pkgInfo`file 
,my.q
q) not 11h ~ type key pkgInfo`file
0b

Was it intended?

I propose changing the line to:

file:` sv f,$[f~k:key f:pkgInfo`file;();1=count k;first k;`init.q];

That will nicely cover all scenarios:

q).utl.require"my/my.q"    / file loading scenario
q).utl.require"my"         / dir loading scenario; supports single-file dir with or without init.q
@nugend
Copy link
Owner

nugend commented Aug 12, 2021

Hm. You know I don't know if I completely remember the reasoning for doing it just this way. I think I was just emulating what Python packages did since I like most of how namespace resolution works in Python 3.

Could you file a PR with a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants