Search code examples
jtacit-programming

How to rewrite the halve function in J?


in the J programming language,

-: i. 5 

the above function computes the halves of all integers in [0,4]. Now let's say I'd like to re-write the -: function, just for the fun of it. My best guess so far was

]&%.2

but that doesn't seem to cut it. How do you do it?


Solution

  • %&2    NB. divide by two
    0.5&*  NB. multiply by one half