I'm not sure this is intended J usage, but how about:

   A =: 1 : 'm*[-]'
   B =: 1 : 'm* -'
   C =: 2 : 'm*n-y'
   D =: 1 : (':'; 'm*y-x') 

Now:
   3 (4) A 5
_8
   3 (4) B 5
_8
   3 C (4) 5
_3
   3 (4) D 5
_8

C is slightly different indeed, but would still satisfy your wishes.
C and D combined:

   E =: 2 : (':'; 'm+n*y-x')
   2 (3) E (4) 5
15

with even 4 'arguments'

Ben Gorte


> Date: Wed, 15 Dec 2010 00:03:38 -0000
> From: "Graham Parkhouse" <graham.parkho...@ntlworld.com>
> Subject: [Jprogramming] Explicit adverbs
> To: <programming@jsoftware.com>
> Message-ID: <007f01cb9beb$87da1f70$978e5e...@parkhouse@ntlworld.com>
> Content-Type: text/plain;     charset="us-ascii"
>
> How can I write an adverb that returns a noun from 3 noun arguments x,
m and y as a *one liner*?>
>
> Just 2 arguments is fine:
>    adv1=: 1 : 'm*y'
>    3 adv1 10
> 30
>
> 3 arguments like this doesn't work:
>   adv2=: 1 : 'm*y-x'
>   5 (3) adv2 10
> |domain error
> |   5    (3)adv2 10
>
> Giving it a body works:
>    adv3=: 1 : 0
> :
> m*y-x
> )
>    5 (3) adv3 10
> 15
>
> Is there a way to do it as one liner?
>
> Regards
>
> Graham Parkhouse
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to