Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 863
nes1983 Avatar asked Dec 30 '22 09:12

nes1983


2 Answers

%&2    NB. divide by two
0.5&*  NB. multiply by one half
like image 68
ephemient Avatar answered Feb 07 '23 13:02

ephemient


Note that ] % 2: would also work, but to ensure proper grammar you would either want to use that as the definition of a name, or you would want to put the expression in parenthesis.

like image 32
rdm Avatar answered Feb 07 '23 11:02

rdm