Scripts/QDoJ

From J Wiki
Jump to navigation Jump to search

download a script: File:Qdoj.ijs

require 'files strings'
require jpath '~system\extras\util\help.ijs'

NB.  For the curious, the definition of trim is the same as 'deb' except it
NB.  treats TABs like spaces.  IE:
NB.  ". 'trim =: '  ,    (''' ''&~:'  ;  '-.@:e.&('' '',TAB)') stringreplace 5!:5<'deb'

HTML_ENT =:  <@:(('&'&,@:,&';'@:{. ,&:< }.@:}.)~ i.&'=')@:deb;._2 noun define
	lt=<
	gt=>
	amp=&
	#149=*
	nbsp=
      harr=<==>
)

seq      =:  ((&.>) /) (@:((|.@:[) , (<@:]))) (>@:)          NB.  Due to Jose Quintana
rb       =:  ] #~ (0&~:@:(+/\@:(-/)) +: {:)@:(E.&> boxopen)
html     =:  HTML_ENT&(stringreplace seq)@:('<>'&rb)

qdoj     =:  dyad define  NB.  Quote dictionary of J
	try.
		x (html;.0~ ,:/)"_ 1~  > {. fread @: jpath each ('~system\extras\help\dictionary\';'.htm')  <@:;@:(1&A.)@:,"1 0  y (,&(<y)@:{:@:] {~ {.@:] i. ;:@:[) |: ;:@:-.&'?';._2 toJ DICTNDX_jhelp_
	catch.
		'topic not found'  assert 0
	end.
)

NB.  EXAMPLES:


NB.    1508 100 qdoj '#.'
NB. An atomic argument is reshaped
NB. to the shape of the other argument.
NB.

NB.    QUOTES =: (,. (_2: ]\ 0&".)&.>)/@:(0 _1&{)@:|: ;:;._2 noun define
NB.      !. : 1035 250   1620 99
NB.      <  : 1352 255
NB.      =  : 1719 240
NB. )

NB.    ; <@:(,&CRLF)@:deb"1   qdoj~&>/"1  QUOTES
NB. This conjunction modifies certain verbs in ways prescribed
NB. in their definitions. For example, =!.t is the relation of
NB. equality using tolerance t , and ^!.r
NB. is the factorial function so defined that
NB.
NB. < <: > >: +. *. -. -: | E. i. i:
NB. * Tolerance
NB.
NB. x<y is 1 if x is tolerantly
NB. less than y . See Equal (=) for a definition of
NB. tolerance. <!.t uses tolerance t
NB.
NB. If x or y is a floating-point or complex number,
NB. the comparison is made with a tolerance t ,
NB. normally 2 to the power _44 but also controlled by the
NB. fit conjunction !.