I apologize for the noise.  This message version is corrected.


Thank you, that was insight I had hoped for.

Your solution fits many circumstances.  Perhaps, in general,

f=: u&:(['description')"u

Hence the conjunction Describe

   Dyad=: [: :
   Monad=: :[:

   Describe=: 2 : 'u&:([n"_)"u'

   add=: +Describe'addition' Dyad

   3 <@add i.5
┌─┬─┬─┬─┬─┐
│3│4│5│6│7│
└─┴─┴─┴─┴─┘
   3 <@:add i.5
┌─────────┐
│3 4 5 6 7│
└─────────┘

   add
[: :(+&:([ 'addition'"_)"0 0 0)

   mp =: +/ .*~~ Describe 'vector length squared : dot product'

   mp
+/ .*~~&:([ 'vector length squared : dot product'"_)"_ _ _

   mp 3 4
25

  3 4 ; (i. 2 5) ; 3 4 mp i.2 5
┌───┬─────────┬──────────────┐
│3 4│0 1 2 3 4│20 27 34 41 48│
│   │5 6 7 8 9│              │
└───┴─────────┴──────────────┘




> Date: Wed, 28 Feb 2018 23:12:49 GMT
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] self documentation
> Message-ID: <[email protected]>
>
> David Lambert:
>> Dyad=: [: :
>> add=: +&:([ 'x add y yields the sum x + y'"_) Dyad
> Unlike +, the "add" has ranks _ _ which will be noticable with enough
> context:
>
>    1 <@add i. 4
> +-------+
> |1 2 3 4|
> +-------+
>    1 <@+   i. 4
> +-+-+-+-+
> |1|2|3|4|
> +-+-+-+-+
>
> Given that that you are ditching the monadic case anyway here,
> it's simpler (and rank-preserving) to use u:v here:
>
>    add =. 'x add y yields the sum x + y'"_ : +
>
> or, with your Dyad-style protection against misuse:
>
>    add =. [:&'x add y yields the sum x + y' : +
>
>                             Martin

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

Reply via email to