Re: [Jprogramming] Origin of definitions (was Programming Digest, Vol 174, Issue 7)

2020-03-08 Thread Kirk Iverson
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 [ f=. 32=3!:0 y
 x=. #&' '^:(2~:3!:0) x NB. integer N means N blanks
 m=. 1"0 s=. '\/'&.> 4!:3 '' [ si=. 4!:8 ''
 if. *#y do. NB. filter by y if non-empty
   if. (#m)~:i=. 1 i.~ m=. s={:"1 scrtree1"1 (^:(-.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=. 

Re: [Jprogramming] Origin of definitions (was Programming

2020-03-08 Thread Hauke Rehr

That’s true for the most simple cases only.
That way one gets a display of a value rather than of a definition.

Consider these definitions and “definition query”
(as I said, it’s simply a display of value):

   adv =: 1 : 'm&+'
   v =: 5 adv
   v
5&+

In more complicated situations you would want to see the
complete sentence to the right of =: . So it’s good to
have a mechanism easing retrieval of this information.

Am 08.03.20 um 17:45 schrieb David Lambert:

This is great!  Maybe I whereDefined will help me diagnose my qt mysteries.

Meanwhile, let's remember one of the great joys of j that doesn't happen
with most other languages.  We get the definition directly.

echo
0 0 $ 1!:2&2


Date: Sat, 7 Mar 2020 14:28:05 -0500
From: Devon McCormick 
To: J-programming forum 
Subject: Re: [Jprogramming] Origin of definitions (was Programming
 Digest, Vol 174, Issue 7)
Message-ID:
 
Content-Type: text/plain; charset="UTF-8"

I've used this, courtesy of Dan Bron, for years:
whereDefined=: 3 : '(4!:4{.;:y) {:: (4!:3),<''Source of definition not
found for '',''.'',~y'
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
--
mail written using NEO
neo-layout.org

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Origin of definitions (was Programming

2020-03-08 Thread David Lambert
This is great!  Maybe I whereDefined will help me diagnose my qt mysteries.

Meanwhile, let's remember one of the great joys of j that doesn't happen
with most other languages.  We get the definition directly.

   echo
0 0 $ 1!:2&2


Date: Sat, 7 Mar 2020 14:28:05 -0500
From: Devon McCormick 
To: J-programming forum 
Subject: Re: [Jprogramming] Origin of definitions (was Programming
Digest, Vol 174, Issue 7)
Message-ID:

Content-Type: text/plain; charset="UTF-8"

I've used this, courtesy of Dan Bron, for years:
whereDefined=: 3 : '(4!:4{.;:y) {:: (4!:3),<''Source of definition not
found for '',''.'',~y'
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Origin of definitions (was Programming Digest, Vol 174, Issue 7)

2020-03-07 Thread Eric Iverson
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.


On Sat, Mar 7, 2020 at 2:29 PM Devon McCormick  wrote:

> I've used this, courtesy of Dan Bron, for years:
> whereDefined=: 3 : '(4!:4{.;:y) {:: (4!:3),<''Source of definition not
> found for '',''.'',~y'
>
>
> On Sat, Mar 7, 2020 at 1:47 PM 'robert therriault' via Programming <
> programm...@jsoftware.com> wrote:
>
> > Mind blown. Would there not be a good argument to have it combined into a
> > defined verb?
> >
> >origin =: (4!:3 '' ) {::~ (4!:4 @ <)
> >origin 'echo'
> > /Users/bobtherriault/j901/system/main/stdlib.ijs
> >origin 'init'
> > /users/bobtherriault/j901/addons/ide/jhs/jfiles.ijs
> >origin 'init_jhs_'
> > /users/bobtherriault/j901/addons/ide/jhs/core.ijs
> >
> > Cheers, bob
> >
> >
> > > On Mar 7, 2020, at 09:51, Brian Schott  wrote:
> > >
> > > This is a very handy trick.
> > > Because the Subject of this thread is so uninformative, I have
> Forwarded
> > it
> > > to myself after changing the Subject.
> > >
> > > On Sat, Mar 7, 2020 at 12:05 PM Raul Miller 
> > wrote:
> > >
> > >>   4!:4<'echo'
> > >>
> > >> 1
> > >>
> > >>   1{::4!:3''
> > >>
> > >> /j/system/main/stdlib.ijs
> > >>
> > >>
> > >> https://www.jsoftware.com/help/user/lib_stdlib.htm
> > >>
> > >>
> > >> Thanks,
> > >>
> > >>
> > >> --
> > >>
> > >> Raul
> > >>
> > >> --
> > > (B=)
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > --
> > 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


Re: [Jprogramming] Origin of definitions (was Programming Digest, Vol 174, Issue 7)

2020-03-07 Thread Devon McCormick
I've used this, courtesy of Dan Bron, for years:
whereDefined=: 3 : '(4!:4{.;:y) {:: (4!:3),<''Source of definition not
found for '',''.'',~y'


On Sat, Mar 7, 2020 at 1:47 PM 'robert therriault' via Programming <
programm...@jsoftware.com> wrote:

> Mind blown. Would there not be a good argument to have it combined into a
> defined verb?
>
>origin =: (4!:3 '' ) {::~ (4!:4 @ <)
>origin 'echo'
> /Users/bobtherriault/j901/system/main/stdlib.ijs
>origin 'init'
> /users/bobtherriault/j901/addons/ide/jhs/jfiles.ijs
>origin 'init_jhs_'
> /users/bobtherriault/j901/addons/ide/jhs/core.ijs
>
> Cheers, bob
>
>
> > On Mar 7, 2020, at 09:51, Brian Schott  wrote:
> >
> > This is a very handy trick.
> > Because the Subject of this thread is so uninformative, I have Forwarded
> it
> > to myself after changing the Subject.
> >
> > On Sat, Mar 7, 2020 at 12:05 PM Raul Miller 
> wrote:
> >
> >>   4!:4<'echo'
> >>
> >> 1
> >>
> >>   1{::4!:3''
> >>
> >> /j/system/main/stdlib.ijs
> >>
> >>
> >> https://www.jsoftware.com/help/user/lib_stdlib.htm
> >>
> >>
> >> Thanks,
> >>
> >>
> >> --
> >>
> >> Raul
> >>
> >> --
> > (B=)
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> 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