Here are a couple related verbs which may be useful when dealing with this
sort of stuff:
which - return script which defined name
scrtree - return script calling tree
junpath - "undo" jpath by (replace prefixes with ~codes)
/K
NB./ which - return script which defined name in y
NB./ [x] - if _ (default), just return script defining name
NB./ else, invoke scrtree to return script call tree (with x as left
arg)
NB./ y - name
NB./ (boxed y indicates return full pathnames)
which=: verb define
_ which y
:
y=. >y [ f=. 32=3!:0 y [ t=. -.x-:_
s=. junpath^:(-.f) >(4!:4 <y){(4!:3 ''),<'(undefined)'
x&scrtree^:t@(<^:(t*.f))^:('('~:{.s) s
)
NB./ scrtree - return script calling tree
NB./ Return list of loaded scripts with indentation to show call
relationships.
NB./ [x] - "indent": literal to be used to indent levels
NB./ or integer for number of blanks
NB./ y - empty: return entire script tree
NB./ script name: return only script and its ancestors
NB./ (boxed y indicates return full pathnames)
scrtree=: verb define
y scrtree~ (-.(<y)e. '';<<'')}.' ',~_2{9!:6 ''
:
y=. >y [ f=. 32=3!:0 y
x=. #&' '^:(2~:3!:0) x NB. integer N means N blanks
m=. 1"0 s=. '\/'&charsub&.> 4!:3 '' [ si=. 4!:8 ''
if. *#y do. NB. filter by y if non-empty
if. (#m)~:i=. 1 i.~ m=. s=<jpath y do.
while. i~:_1 do. i=. i{si [ m=. 1 i}m end.
end.
end.
lev=. 3 : '>{:"1 scrtree1"1 (<y),"0 1 (<"0 y),.<0'
}:; (m#junpath&.>^:(-.f) s) (LF <@,~ [ ,~ ] $ x"_)&> (#x)*m#lev si
)
scrtree1=: verb define
'si i c'=. y
if. i=_1 do. y return. end.
scrtree1 si;(i{si);>:c
)
NB./ junpath - inverse of jpath
NB./ Return pathnames in y, replacing prefixes with
NB./ "~abc" prefixes from System/UserFolder
junpath=: verb define
y=. boxxopen y [ isb=. 32=3!:0 y
p=. (\: #@>@:({:"1))SystemFolders_j_,UserFolders_j_
isprefix=. 4 : '(m{.x)-:y{.~m=. x<.&#y'
i=. (m=. (*@#@>y)*.i~:#p)#i=. i.&1"1 (({:"1 p),&.>'/') isprefix&>/~ y
y=. y (I.m)}~ (i{'~',&.>{."1 p),&.>(i{#@>{:"1 p)}.&.>m#y
>^:(-.isb) y
)
From: Eric Iverson <[email protected]>
> To: Programming forum <[email protected]>
> Subject: Re: [Jprogramming] Origin of definitions (was Programming
> Digest, Vol 174, Issue 7)
> Message-ID:
> <
> capropvj3riq6-w3t9brhlvboj7nobpifdq2iycsbairb7tt...@mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> A search in files for 4!:3 finds verb whichscript defined in
> ~addons/misc/miscutils/utils.ijs. I suggest we lobby Chris to have this (or
> a variant) included in stdlib and somehow spread knowledge of its
> existence.
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm