I was about to post this as a question but finally figured out the answer. I'll 
post it anyway in case it is of help to others:

I want to create a verb "defverb" such that
  'myname' defverb '<my sentence>'
assigns <my sentence> to a new verb 'myname'

So if <my sentence> was: 
% *: y
I'd end up with a monadic verb called myverb that took the right argument, 
squared it and found the reciprocal.

   ('myverb')=: 3 : '% *: y'    NB. This works

   tstx=: 'myverb2'
   tsty=: '% *: y'
   (tstx)=: 3 : tsty            NB. This works

   verbstr=: 4 : '(x)=: 3 : y'  NB. define verb to do it
   verbstr
4 : '(x)=: 3 : y'               NB. looks ok
   'myverb3' verbstr '% *: y'   NB. Doesn't work!
|syntax error: verbstr
|   'myverb3'    verbstr'% *: y'

Why?







An explicit verb is only allowed to return a noun.   
<http://www.jsoftware.com/help/dictionary/d310n.htm>
Solution.
   verbstr=: 4 : ('(x)=: 3 : y';'$0')

   'myverb3' verbstr '% *: y'
   myverb3 4 3
0.0625 0.111111

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to