A conjunction that returns an adverb and applies its 2 arguments before and 
after the adverb's parameter.

B =: 2 : '(@: u)(v @:)'

  >: +:B -: 2 
2.5 
  >: &.+: 2 
2.5 

  >: dfh B hfd '1a' 
1b 


The verbs are placed counterintuitively under the presumption that the u verb 
will be longer, and so this avoids parentheses.  Also the u side is what 
modifies the adverb parameter.

dfh and hfd are not defined as inverses, and this also lets you setup up 
bracketed operations independently of they being inverses.

A bit more complex of a between conjunction, where the closer also uses the 
same y parameter (as its x):

Bwy =: 2 : ' 1 : (''] ('' , v lrA , '') [: '', '' u ('' , (u lrA) ,'')"_'')'
sfX =: 1 : '][u' NB. apply u, but keep y as the result.  

 +: +:Bwy(-~) 
] -~ [: +: +:"_ 
 +: +:Bwy(-~) 2 
6 


for a useful example,

 '1' fwrite jpath '~temp/1.cnt' 
1

 withFile =: &.". fread Bwy (fwrite~ sfX) NB. adverb that will apply operation 
to file then save it.

 >: withFile 
] (] [ fwrite~) [: >:&.". fread"_ 
 
 >: withFile jpath '~temp/1.cnt' 
2

Another bracketing type application is for "ensure even if error" code.  Can't 
seem to decide what should be u and v, as this is inverted compared to above:

BetweenE =: 2 : ' 1 : (''([: ('' , u lrA , '') [: '', '' u ('' , (v lrA) 
,'')"_) :: (''  , u lrA , '')'' )'
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to