4 ms·
> "learn an array language, they're easy to write on paper" everyone would think they were insane... but there is something to it, in certain cases. Indeed, an
by bear8642 3y ago
> "learn an array language, they're easy to write on paper" everyone would think they were insane... but there is something to it, in certain cases.
Indeed, and sometimes not needing a computer to quickly splash out an idea you're thinking/talking about is extremely useful!
Over Christmas, I showed my brother {+⌿⍤2(∘.≤)⍤1⍨⍵} as a small expression to explore attribute to pick playing Top-Trumps admist a discussion. Not something you'd be able to do in many other languages!
- Affric 3y agoCould you explain the expression to us?
- bear8642 3y agoSure - idea is you've got a 6×30 matrix of the 6 card attributes for each of the 30 cards, and want to know for each attribute how many other cards they'd beat. {+⌿⍤2(∘.≤)⍤1⍨⍵} { ⍵} ⍝ single argument (monadic) function with argument ⍵ { ⍨⍵} ⍝ "selfie" - ⍵ f ⍵ where f is (∘.≤)⍤1 { ⍤1⍨⍵} ⍝ on each row (1 dimensional element) { (∘. )⍤1⍨⍵} ⍝ cartesian (outer) product of each row with itself { (∘.≤)⍤1⍨⍵} ⍝ ≤ comparison of those elements - produces 6 30×30 boolean matrices { ⍤2(∘.≤)⍤1⍨⍵} ⍝ on each of those matricies (2 dimensional element) {+⌿⍤2(∘.≤)⍤1⍨⍵} ⍝ sum the columns leading to: {+⌿⍤2(∘.≤)⍤1⍨⍵} ⍝ compare each row (⍤1) to itself (⍨) and count (+⌿) how many cards that beats That make sense?
- Affric 3y agoThat's great and you have sent me down the rabbit hole. So, usage would be something like: CardPower ← {+⌿⍤2(∘.≤)⍤1⍨⍵} CardPower cardMatrix
- bear8642 3y agoYep, or even apply inline as {+⌿⍤2(∘.≤)⍤1⍨⍵}cardMatrix
- Affric 3y agoThinking about your comment further (and having read TFA and some of the comments) inline usage does seem to make more sense as it's only a few more characters. In that way it's transparent. Decreasing indirection (assuming that the operators always function simply and plainly. Thanks for that follow up comment.