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

2014-05-11 Thread David B. Lamkins
Um, yes and no. This was all hacked together during compilation breaks while at work. I didn't put any effort into testing edge cases. In particular, I assumed string keys. I didn't design for or test with numeric keys. Also, `me' was designed as a helper for `nl'. In combination with `nl' and f

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

2014-05-11 Thread Blake McBride
Is this what you intended of the 'me' function: ≡me 4 3 ≡me 5 6 2 ≡me '' 2 ≡me 'f' 3 ≡me 'ff' 2 ≡me 'aaa' 'bbb' 3 ≡me 'a' 'b' 2 On Fri, May 9, 2014 at 4:00 PM, David B. Lamkins wrote: > Here's a version that doesn't use a lambda. Instead, there's a ne

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

2014-05-09 Thread David B. Lamkins
Here's a version that doesn't use a lambda. Instead, there's a new function `findl' that captures `list' from its caller (`finds'). ∇z←list find key z←key≡¨list ∇ ∇z←findl key z←(nl list) find ⊂key ∇ ∇z←list finds keys z←findl¨nl keys ∇ ∇z←me e z←⊂(⎕io+≡e)⊃(⊂,e) (,e) (e) ∇ ∇z←nl l z←me¨(⎕

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

2014-05-09 Thread David B. Lamkins
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 k

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

2014-05-09 Thread Blake McBride
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. Thanks for the help! Blake On Fri, May 9, 2014 at 11:39 AM, David B. Lamkins wrote: > That particular function is not designed to accept multiple keys. > > > On Fri,

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

2014-05-09 Thread David B. Lamkins
That particular function is not designed to accept multiple keys. On Fri, 2014-05-09 at 11:34 -0500, Blake McBride wrote: > Greetings, > > > It doesn't work: > > > m←'hello' 'there' 'how' 'are' 'you' > m > hello there how are you > > > m find 'are' > 0 0 0 1 0 > m

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

2014-05-09 Thread Blake McBride
Greetings, It doesn't work: m←'hello' 'there' 'how' 'are' 'you' m hello there how are you m find 'are' 0 0 0 1 0 m find 'are' 'hello' 0 0 0 0 0 'are' find m 0 0 0 Thanks. Blake On Fri, May 9, 2014 at 11:15 AM, David B. Lamkins wrote: > Try this: > > ∇z←list fi

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

2014-05-09 Thread David B. Lamkins
Try this: ∇z←list find key z←(,¨list)∊⊂,key ∇ (Also: please trim your replies.) On Fri, 2014-05-09 at 10:26 -0500, Blake McBride wrote: > Interesting. I didn't know about ≡. That's helpful, but the issue > you raise with 'a' 'b' leaves us back to where I started. There > should be a simple w

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

2014-05-09 Thread Blake McBride
Interesting. I didn't know about ≡. That's helpful, but the issue you raise with 'a' 'b' leaves us back to where I started. There should be a simple way for me to determine whether to do ⊂ or not. I just haven't figured out how. I read that there was a big debate about what ⊂ does on a scalar.

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

2014-05-09 Thread Elias Mårtenson
How would you do that? The problem here is that you as a person see 'foo' and think of it as a string in this context and that you want to match on it. However, the ∊ function sees an array of elements (those elements being characters) so it acts upon them. I suppose the best you can do would be t

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

2014-05-09 Thread Blake McBride
Thanks for the tutorial. In my case, however, I already knew that. More specifically, my problem is: x←'hello' 'there' 'how' 'are' 'you' ∇r←test v r←(⊂v)∊x ∇ This works for: test 'there' But doesn't work for: test 'there' 'are' I know I can remove the ⊂ for the second case. I need a sing

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

2014-05-09 Thread Elias Mårtenson
I was very confused about this when I started learning APL too (well documented in this very mailing list's archive). What happens can be illustrated by boxing the output. Let's look at a string: * 8⎕CR 'foo'* ┌→──┐ │foo│ └───┘ * ⍴'foo'* 3 In order words,this is a three-element array o

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

2014-05-09 Thread Blake McBride
Greetings, On Fri, May 9, 2014 at 12:10 AM, Daniel H. Leidisch wrote: > Hello! > > Blake McBride > writes: > > > x←'abcd' 'efg' 'hijkl' > > > > Now, if I have: > > > > y←'hijkl' > > > > z←'hhh' > > > > How can I tell if y is in x? How can I tell if z is in x? > > Or for both at once: > >

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

2014-05-09 Thread Blake McBride
Thanks to all! Very cool! I feel comfortable creating, unpacking, and moving general arrays, but that's the extent of it. I'll have to get some of this new stuff in my head. Thanks for the help! Blake On Fri, May 9, 2014 at 12:10 AM, Daniel H. Leidisch wrote: > Hello! > > Blake McBride >

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

2014-05-09 Thread Daniel H. Leidisch
Hello! Blake McBride writes: > x←'abcd' 'efg' 'hijkl' > > Now, if I have: > > y←'hijkl' > > z←'hhh' > > How can I tell if y is in x? How can I tell if z is in x? Or for both at once: (y z)∊x 1 0 Regards, Daniel

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

2014-05-09 Thread Daniel H. Leidisch
Hello! Blake McBride writes: > x←'abcd' 'efg' 'hijkl' > > Now, if I have: > > y←'hijkl' > > z←'hhh' > > How can I tell if y is in x? How can I tell if z is in x? (⊂y)∊x Regards, Daniel

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

2014-05-08 Thread Elias Mårtenson
And of course, it can be made generic using ¨: * x ← 'foo' 'bar' 'this' 'is' 'a' 'list' 'of' 'strings'* * x ≡¨ ⊂'bar'* 0 1 0 0 0 0 0 0 Regards, Elias On 9 May 2014 13:35, David B. Lamkins wrote: > The outer product approach is APL 1. > > In APL 2, you can enclose the search term and

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

2014-05-08 Thread David B. Lamkins
The outer product approach is APL 1. In APL 2, you can enclose the search term and test for membership in the list: ll←'abd' 'defgh' 'ij' 'klm' ll∊⊂'ij' 0 0 1 0 ll∊⊂'foo' 0 0 0 0 On Thu, 2014-05-08 at 22:56 -0500, Blake McBride wrote: > Forgive the question, but my experience

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

2014-05-08 Thread Elias Mårtenson
It's easier than that. Your solution is: *∨/ (⊂'bar') ⍷ x* This is because X⍷Y returns a list of the elements of X that matches Y. Then ∨/ is just a reduction of that. Regards, Elias On 9 May 2014 11:56, Blake McBride wrote: > Forgive the question, but my experience is only with the or