user1202733
user1202733

Reputation: 623

mapping j function (used defined) over a list

I've written my own version of the exponential (^) function which works fine for simple scalars :

3 : '+/ (y&^%!) i.50'

It doesn't work over a list, so I thought of modifying it with "0

3 : '+/ (y"0&^%!) i.50'

This works over a list but gives the wrong answers.

Two questions arise:

1) Given my usage of "0 doesn't work, is there one that does ?

2) If I don't have access to a functional definition like this, what is the best way to apply it to the individual elements of an array ?

Upvotes: 2

Views: 79

Answers (1)

Alex Shroyer
Alex Shroyer

Reputation: 3829

You need to apply the rank conjunction "0 over the function you want to map (y&^%!), instead of its argument y:

 3 : '+/(y&^%!)"0 i.50'

However, the precision isn't as good as the native ^:

   a =: 3 : '+/(y&^%!)"0 i.50' 4 4 $ 10+i.20
   b =: ^ 4 4 $ 10+i.20
   a = b
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0

Upvotes: 1

Related Questions