Or it could be set by each 1!:1 file read, for example. Or, it could be a left to the 0!: verb. This eliminates accidental bogus values where the script did not come from a file and/or the MYFILE value was stale.
Thanks, -- Raul On Fri, Aug 24, 2018 at 3:51 PM 'Pascal Jasmin' via Programming <[email protected]> wrote: > > This is about finding "MYFILE or MYDIR" from within a script in a portable > manner from different computers. (so avoiding hardcoding filenames/paths in > code) > > I do this with this line pasted in files that need it > > MYDIR =: getpath_j_ '\/' rplc~ > (4!:4<'thisfile'){(4!:3) thisfile=:'' NB. > boilerplate to set the working directory > > the 4!:3 list gets apparently updated by the J system before 0!:n processes > the file. Updated with a filename. Not updated if a noun is generated from > the file contents, and 0!:n called on that noun. > > My workaround is designed to still work when the regular J process for load > from file is used, but also work when files are preprocessed (to > remove/expand invalid J syntax into J syntax) replacing toplevel lines > starting with MYDIR =: with a hardcoded value (the load command overridden to > make this replacement, as well as any desired preprocessing before invoking > 0!:n on the resulting noun) > > To be useful to others, MYDIR would be a magic noun, if they used my > extension (jplusplus) > > > On Friday, August 24, 2018, 3:20:01 p.m. EDT, Raul Miller > <[email protected]> wrote: > > > > > > Note that you can append a: (or whatever other boxed string) to the > value from 4!:3 before indexing with the result from 4!:4 > > Perhaps having the system do this would be a slight convenience? > > Thanks, > > -- > Raul > > On Fri, Aug 24, 2018 at 2:57 PM 'Pascal Jasmin' via Programming > <[email protected]> wrote: > > > > Rewriting scripts and then invoking them with 0!:0 noun (instead of file) > > has the disadvantage of "breaking" 4!:4. If 4!:4 is ever used on a > > definition from the file, it will report _1 (definition not from a script). > > This applies to definitions inside the original file, often used to find > > the directory of the program, and used to load related files and data. > > The perfect solution is to add an optional left argument to 0!:n noun which > > would be the filename returned by 4!;4 for definitions inside that noun. > > A solution I can do myself, applies if the only real use for 4!:4 is in > > fact to find "MYFILE" in a script. > > The solution is to replace in the file all top level instances of lines > > starting with (space intollerant) > > MYDIR =:MYFILE =: (NB. not sure if this is needed, as the file is usually > > obtained just to get MYDIR) > > with a hardcoded string derived from what the x argument (MYFILE) to 0!:n > > should be. > > If this function over-rode the load command, then 4!;4 would return empty > > for most definitions, which is only a problem if 4!:4 is ever used for > > anything other than on a variable within its own script . > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
