I was composing the following when your message arrived:
When you load a script and run it, it runs in your current working
directory, e.g.:
1!:43''
C:\Program Files\j602\bin
after I first start J. So, a script does not have its own, intrinsic,
pathname: either you know from where you loaded it, or you can find the
location of something you know is defined in that script, e.g. for the
script "C:/amisc/J/wheresMyCar.ijs" which looks like this:
fread 'C:/amisc/J/wheresMyCar.ijs'
NB.* wheresMyCar.ijs: show path at which this script was defined.
HeyDude=: 0
NB. whereDefined 'HeyDude'
I could load it (but I already have to know its path) and ask where the
known definition is from:
load 'C:/amisc/J/wheresMyCar.ijs'
whereDefined 'HeyDude'
C:\amisc\J\wheresMyCar.ijs
(where whereDefined=: 3 : '(4!:4{.;:y) {:: (4!:3''''),<''Source of
definition not found for '',''.'',~y' )
Hope this helps.
BTW, "getpath" could be simplified:
getpath=: 3 : 0
dirname=: #~ '/\' +./\...@e.~ ]
dirname (4!:4<'dirname') {:: 4!:3''
)
The problem is, if you put this in every script, your answer will be based
on whatever you last loaded.
On Thu, Apr 8, 2010 at 12:37 PM, Sprague, Webb (OFM) <
[email protected]> wrote:
> With many thanks to the J programming forum, here is my solution to the
> problems of (1) finding my script's path and (2) loading libraries
> relative to that path:
>
> NB. Load this file with "load 'Z:\blah\J-experiments\getpathsample.ijs'
> NB. Then call the following as "pth =. getpath ''".
> getpath =: 3 : 0
> dirname=: #~ '/\' +./\...@e.~ ]
> sourcepath=: dirname (4!:4<'dirname') {:: 4!:3''
> sourcepath
> )
>
> NB. Now you can do the following in a J session
> NB. pth =. getpath ''
> NB. scriptpth =. pth,'..\J-experiments\loadable.ijs'
> NB. load scriptpth
> NB. x =. foobar '' NB. this function is defined in loadable.ijs
>
> Thanks again for everyone's help (and forgive me if I am offending any
> sensibilities...)!
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm