Definition of Verbs (functions, procedures or operators) in J, Feb 1994. ------------------------------------------------------------------------- a) All functions have either one (monadic) parameter eg. f y or have two (dyadic) parameters eg. x f y b) Functions can be defined `explicitly' using : x. y. $. or `tacitly' in combinator style. eg. mean =. +/ % # c) It is not necessary to give a name to a function using =. see self-reference $: Explicit Definition : ---------------------- takes a list of boxed strings (optionally a single string) for its left and right arguments. The left argument is the "code" for the monadic case and the right argument is the code for the dyadic case. x. is the left parameter, if any, y. is the right parameter. NB. it is safest to put a space either side of the colon as it is the second character of many verbs! fiblist =. ('r =. 0 1' ; '$. =. y. # 2' ; 'r =. r , +/ _2{. r') : '' ^ ^ | | | no dyadic case here monadic case fiblist --> +------------------+-++ 0: |r =. 0 1 |:|| 1: |$. =. y. # 2 | || <--suite $. =. 2 2 2... y. times 2: |r =. r , +/ _2{. r| || +------------------+-++ ^ ^ ^ | | | | | last 2 elts of r _2 {. r | |----add them +/ |------and append to r , fiblist 6 --> 0 1 1 2 3 5 8 13 Note: r is local to fiblist result is last expression executed, ie. r y. is the (right) parameter of fiblist $. is initially 0 1 2 but becomes 2 2 2 .... y. times Don't get carried away into Fortran or Basic style! If sentence k begins with a name followed by ) eg. lab) then the name is local and is set to k }. i. ns ie. $. =. lab sets suite $. to k (k+1) ... for branching. NB. m : 1 yields an adverb m : 2 is a conjunction m :20 explicit -> tacit defn of verb if possible m :21 explicit -> tacit defn of adverb m :22 explicit -> tacit defn of conjunction Tacit Definition ---------------- uses combinator-style programming without explicit mention of parameters x. and y. mean =. +/ % # tacit definition: sum divided by length code =. '(+/ y.) % (# y.)' sum +/ of y. divided % by length # of y. MEAN =. code : '' explicit definition mean =. code : 20 : 20 converts explicit to tacit if possible mean --> +-----------+-+-------+ |+-----+-+-+|%|+-+-+-+| ||+-+-+|@|]|| ||#|@|]|| |||+|/|| | || |+-+-+-+| ||+-+-+| | || | | |+-----+-+-+| | | +-----------+-+-------+