This control structure is a variation on the / adverb.
There is both an adverb form, and more general
conjunction form.  The adverb u ListBlocK 1 2 3 4 is
equivalent to:
(1 u 2 3 4) , (2 u 3 4) , (3 u 4)

The more general conjunction form (u ListBlock v) 1 2
3 4 is equivalent to:
(1 u 2 3 4) v (2 u 3 4) v (3 u 4)

and also equivalent to
v/ (u ListBlocK) 1 2 3 4

The control structure is more equivalent to
lisp/haskell style which use explicit functions that
have the entirety of the tail available as a parameter
to combine with successive head items.  The most
practical operation is relationship testing between
members and the rest of the list, in n*n/2 time
instead of n*n.

ListBlock=: 2 : 0
 NB. Loops through list passing head u rest to dyad u.
 NB. results accumulated to lastreturns v newresult
 NB. Purpose: like / but passes full rest of list on
right.
 try.  last=. (v/ i.0) catch.  last=. i.0 end.  NB. v
must have an identity function defined, or otherwise
deal with i.0 v (h u y).
 while. 1<#y [ 'h y' =. xxs y do. 
  last=. last v h u y
 end.   
 last=. last v h u y
)
ListBlocK=: (ListBlock ,)

   f=: 4 : 'x + +/ y'
  (f ListBlocK) 1 2 3 4
10 9 7
   (f ListBlock +) 1 2 3 4
26

Maybe InsertWhole would be a better name for it?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to