eval =: 1 : ' a: 1 :  m'

u2m =: 1 : (':';'x m eval y')
v2n =: 2 : (':';'x  (u v eval) y') 
v2nS =: 2 : (':';'x  (v eval u) y')

u2m is limited to monadic result verbs, but because you can build the 
parameters, you can also create bound verbs:

   '+' (] (' eval' u2m)~ '3&' ,[) 2 
5

the parameter to u2m is a string that is an adverb, and where that adverb takes 
a noun as a parameter.

(' eval' u2m) is a verb, that can be set to passive (~).  The above can also be 
called as

  ('3&+' (' eval' u2m) ]) 2 
5 

but the point of the previous example was to show that the string could be 
built as a verb, even though the adverb can only accept nouns.

can also be used to build adverbs such as amend.  example where 3 is a constant 
replacement value, but the index to update is passed through x.

   1    (('13&(' , '})' ,~ ":@:[)(' eval'u2m) ])i.5 
0 13 2 3 4 

    0 ([ (+:`+ v2n ' @.') ]) 2 
4 
    (1: (+/ v2n ' "') ]) i. 2 3 
3 12 

For v2n, a conjunction is first bound to its u argument (v2nS binds v first 
instead)  The first bound argument does not need to be a noun.  The result is a 
verb that will take x to complete the conjunction the "normal way" that it 
would be when first bound into an adverb.  The n parameter though, can now be a 
verb.

the above 2 examples do:
+:`+@.0 ] 2
+/"1 i. 2 3

though I haven't found a way to make the v2n result a dyad, you might use u2m 
and eval instead:

   1 2 ((":@:[ , ' &(+"' , ')' (,~ ":) 0 , 1:) ('eval' u2m) ]) i.3 
1 2 3 
2 3 4 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to