bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] String element of general array


From: David B. Lamkins
Subject: Re: [Bug-apl] String element of general array
Date: Fri, 09 May 2014 12:55:11 -0700

This is a lot easier in Lisp. On the other hand, I've known Lisp for 40
years and am just now learning APL 2. I was pretty good at APL in the
`70s and `80s, but the nested arrays are new to me. I really ought to
read some of Dr. Brown's papers...

Anyhow, I think this ought to help:

∇z←list find key
  z←key≡¨list
∇

∇z←list finds keys
  z←{(nk list) find ⊂⍵}¨nk keys
∇

∇z←me e
  z←⊂(⎕io+≡e)⊃(⊂,e) (,e) (e)
∇

∇z←nk l
  z←me¨(⎕io+1=≡l)⊃l (⊂l)
∇

Feel free to think of more evocative names. 

`me' makes an enclosure regardless of the depth of the incoming item.
Think of this as normalizing a single element.

`nk' was originally `normalize keys'. As you can see though, I'm using
it on both the list and the keys. Maybe `normalize list' would be more
correct.

`find' matches one key against each item of the list, assuming that
everything is already normalized per the above.

Finally, `finds' applies `find' to each key.

The return from `finds' is a list of match vectors, one per key. You'll
have to process this as appropriate for your application.

Here's an example:

      ]boxing 8
      ll←'a' 'bc' 'def' 'foo' 'g'
      ll
┌→───────────────────┐
│a ┌→─┐ ┌→──┐ ┌→──┐ g│
│  │bc│ │def│ │foo│  │
│  └──┘ └───┘ └───┘  │
└∊───────────────────┘
      ll finds 'a'
┌───────────┐
│┌→────────┐│
││1 0 0 0 0││
│└─────────┘│
└∊──────────┘
      ll finds 'bc' 'foo'
┌→──────────────────────┐
│┌→────────┐ ┌→────────┐│
││0 1 0 0 0│ │0 0 0 1 0││
│└─────────┘ └─────────┘│
└∊──────────────────────┘
      ⍝ Beware...
      ll finds 'a' 'g'
┌───────────┐
│┌→────────┐│
││0 0 0 0 0││
│└─────────┘│
└∊──────────┘
      ⍝ ... because:
      'a' 'g'
┌→─┐
│ag│
└──┘
      ll finds (,'a') (,'g')
┌→──────────────────────┐
│┌→────────┐ ┌→────────┐│
││1 0 0 0 0│ │0 0 0 0 1││
│└─────────┘ └─────────┘│
└∊──────────────────────┘


On Fri, 2014-05-09 at 11:46 -0500, Blake McBride wrote:
> Dear David,
> 
> 
> I had a solution to the single key case a while ago (see prior
> messages).  My problem is handling one or more keys.






reply via email to

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