bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] IOTA

 From: Elias Mårtenson Subject: Re: [Bug-apl] IOTA Date: Wed, 2 Mar 2016 10:43:50 +0800

On 2 March 2016 at 10:28, Christian Robert 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

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]