User:Oleg Kobchenko/Namedoc

From J Wiki
Jump to navigation Jump to search

The verb namedoc returns documentation for a name given as parameter. It is similar to scriptdoc, but is suitable to use directly in session.

Examples

namedoc is a handy discovery tool.

   namedoc 'namedoc'
namedoc (v) scriptdoc for a name
e.g. namedoc 'namedoc'
     namedoc 'split'
     ;(namedoc,LF"_,LF"_) &.> _3{.nl_z_''

   namedoc 'split'
split (v) split head from tail
examples:
   split 'abcde'
   2 split 'abcde'

   namedoc 'ss'
ss (v) string search

If verb has no doc, its location is returned.

   namedoc 'setbreak'
defined in /Users/olegyk/j602/system/main/break.ijs

If name is not found, or defined outside of a script file:

   qq=.+
   namedoc'qq'
not found

Definition

The script is based on scriptdoc utility. [{{#file: "namedoc.ijs"}} Download script: namedoc.ijs ]

NB. session documentation utility

require 'scriptdoc'

coclass 'jscriptdoc'

NB.*namedoc v scriptdoc for a name
NB. e.g. namedoc 'namedoc'
NB.      namedoc 'split'
NB.      ;(namedoc,LF"_,LF"_) &.> _3{.nl_z_''
namedoc=: 3 : 0
  'n file'=. y
  tbl=. scriptdef1 'b'fread file
  nam=. {."1 tbl
  if. (#nam) <: nmi=. nam i. <n do.
    'defined in ',>file return. end.
  def=. scriptdeffmt ,:nmi{tbl
  (1+#DEFSEP) }. def
)

namedoc_z_=: 3 : 0
  ndx=. 4!:4 :: _1: y=. boxopen y
  if. ndx < 0 do. 'not found' return. end.
  file=. ndx { 4!:3 ''
  namedoc_jscriptdoc_ y,<file
)

Contributed by Oleg Kobchenko

Comments

As originally defined namedoc would only return documentation for names defined in the jscriptdoc locale and locales in jscriptdoc's copath (i.e. the z locale).

Now namedoc will also return documentation (or the scriptname where the name is defined) for verbs that aren't "redefined" in the z locale, as long as the name is defined in the copath of the current locale.

I have modelled the changes above on how the edit verb works.
Feel free to revert changes if desired.
-- Ric Sherlock <<DateTime(2008-03-27T01:55:48Z)>>