Comment by 1-more
4 months ago
> I love explaining +/%#
Based on the one thing I remember in APL I'm guessing the first two characters are "sum over some data structure" and the data structure is what the next two mean. What does it mean entirely?
4 months ago
> I love explaining +/%#
Based on the one thing I remember in APL I'm guessing the first two characters are "sum over some data structure" and the data structure is what the next two mean. What does it mean entirely?
avg=: +/ % #
+/ sums the items of the array.
# counts the number of items in the array.
% divides the sum by the number of items.
delightful, ty. How does it handle empty arrays? Throw? Average is zero? Average is infinity?
Average is zero
1 reply →
I'd call that code obfuscation.
you would not need an explanation.
> I'd call that code obfuscation.
we call them "trains". since this one has a descriptive name, `avg a`, is not cryptic at all. just a bit fewer of absolutely meaningless parens and duplication.
but it doesn't end there:
1. imagine you wanted a moving average instead. i need to change one character in this train to get `mavg`. what would you need to do?
2. imagine you want to compute moving averages for each of 1000 arrays using both instruction-level parallelism and all available cores? while you'd be writing your unobfuscated code for that, i'd be done way before you're back from your lunch break. in two keystrokes.
once you'd be done with your solution, there would be no need to discuss productivity, or so i hope, but to discuss performance would be interesting.
There's an initial learning curve as there is with any new programming paradigm (which everyone who works exclusively in C-like languages forgets that they paid a long time ago) but there are only something like 100 primitives, and then once you understand how they interact, the world opens up and the volume of a sphere being
Vs=: 4r3p1"_ * ] ^ 3:
just reads normally. It's been over ten years since I did anything in J and I can almost explain that now...
4 replies →
K et al. can look like that, but this example doesn't require any explanation to someone who has any familiarity.
the thing about tacit programming is that it wouldn't use 'a' in the above. if you wrote average in j without it being tacit, it would probably be more readable to you. the question of how to thread data around without naming it is an interesting one to me.
1 reply →