On 2 March 2016 at 10:28, Christian Robert <[email protected]>
wrote:
> IOTA ← {∘.,/⍳¨⍵}
>
> yes, it does the trick (you are really good btw)
>
I don't consider myself good. :-)
Anyway, it's quite simple. Let me break it down:
First of all, ¨⍳⍵ will simply create the individual iotas:
* ⍳¨2 3 4*
┌→──────────────────────┐
│┌→──┐ ┌→────┐ ┌→──────┐│
││1 2│ │1 2 3│ │1 2 3 4││
│└───┘ └─────┘ └───────┘│
└∊──────────────────────┘
The ∘., function will take two lists, and apply the function ,
(concatenate) on each permutation:
* (⍳2) ∘., (⍳3)*
┌→────────────────┐
↓┌→──┐ ┌→──┐ ┌→──┐│
││1 1│ │1 2│ │1 3││
│└───┘ └───┘ └───┘│
│┌→──┐ ┌→──┐ ┌→──┐│
││2 1│ │2 2│ │2 3││
│└───┘ └───┘ └───┘│
└∊────────────────┘
You've probably seen the ∘.× function used to create a multiplication table
in a similar manner.
Finally, the / operator acts on a function and a list as if the function
was placed between every element in the list. Thus:
* ∘., / (1 2) (1 2 3) (1 2 3 4)*
will be equivalent to:
* (1 2) ∘., (1 2 3) ∘., (1 2 3 4)*
Regards,
Elias