Yes, something like it, but ideally, I'd love to be able to boil this down to a one-word flag that we could pass as the right argument to ^: (which would require a patch to `load`)
These command line flags are new to me. I do see them in use on the wiki, but I'm not yet seeing an explanation. Are they documented somewhere? On Wed, Sep 8, 2021 at 12:12 PM Devon McCormick <[email protected]> wrote: > I typically have a line like this in script files: > if. (5{.&.>'-jijx';<'-rt') +./ . e. 5&{.&.>tolower&.>ARGV_z_ do. > ... > This checks the command-line for some flags - "-jijx" or "-rt" - indicating > we are in an interactive session. However, you have to follow a convention > of using these flags whenever you start an interactive session. These are > for jconsole as I rarely use JQt. > > Is this something like what you are looking for? > > > On Wed, Sep 8, 2021 at 11:09 AM Michal Wallace <[email protected]> > wrote: > > > In python, you can use this `if __name__=="__main__":` line in a module, > > and it will only execute the code in that block if you are running the > > module directly. > > > > This allows you to treat the same file as both a standalone application, > > and a library/module that can be imported into another program. (Or just > as > > often often, to run a test suite for just that module as the "standalone" > > version.) > > > > I tried to make the same thing in J > > > > My first thought was to turn on the debugger and inspect the stack to see > > whether or not we're inside of "load", but it turns out that load does > not > > appear in the stack trace unless you enabled the debugger *before* you > > called load. > > > > So instead, I wound up with this: > > > > {{y > > NB. standalone code goes here > > }}^:('repl.ijs' {.@E.&.|. >{.}.ARGV)'' > > > > It works pretty well, assuming the file in question is named 'repl.ijs' > ... > > > > Now I can run my repl as a standalone application, or import it as a > > widget. > > (Yes, I could just make another file for the standalone code, but I > really > > like the python style.) > > > > Does anyone have a better approach? > > > > If load_j_ incremented and decremented a global counter, then you could > do > > this with: > > > > {{y > > NB. standalone code goes here > > }}^:(-.*load_depth)'' > > > > Thoughts? > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > -- > > Devon McCormick, CFA > > Quantitative Consultant > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
