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: Elias Mårtenson
Subject: Re: [Bug-apl] String element of general array
Date: Fri, 9 May 2014 22:19:22 +0800

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 of characters. The third element of this array is the character 'o'.

Here's another example:

      8⎕CR 'foo' 'bar' 'testing'
┌→────────────────────┐
│┌→──┐ ┌→──┐ ┌→──────┐│
││foo│ │bar│ │testing││
│└───┘ └───┘ └───────┘│
└∊────────────────────┘
      ⍴'foo' 'bar' 'testing'
3

This is a three-element array of arrays. The subarrays themselves has the dimensions 3, 3 and 7 respectively. The third element is the string 'testing'.

Since the ∊ function matches each individual element, when passed the string 'foo' it will match each individual one. I.e, the characters 'f', 'o' and 'o'.

Finally, let's look at what the enclose function does:

      8⎕CR ⊂'foo'
┌─────┐
│┌→──┐│
││foo││
│└───┘│
└∊────┘
      8⎕CR ⍴⊂'foo'
┌⊖┐
│0│
└─┘

What the function does is to encapsulate the argument into a single scalar. A scalar has no dimensions, as seen by the fact that ⍴ returned ⍬.

Of course, you could also put the string inside a single-element array. Such array can be constructed as such:

      8⎕CR ,⊂'foo'
┌→────┐
│┌→──┐│
││foo││
│└───┘│
└∊────┘
      ⍴,⊂'foo'
1

The ∊ function will give identical results for that, since it interprets a scalar and a single-element array the same.

I'm a beginner myself, so perhaps I made a mistake in my explanation. I'll leave it to others to fill in any information I have missed.

Regards,
Elias


On 9 May 2014 20:07, Blake McBride <address@hidden> wrote:
Greetings,


On Fri, May 9, 2014 at 12:10 AM, Daniel H. Leidisch <address@hidden> wrote:
Hello!

Blake McBride <address@hidden>
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

I like this best, except:

u←'abcd'
g←'ghjk'  'dsaw'

g∊x   works. but I have to do:

(⊂u)∊x

but:

u∊x doesn't work.

the left side is being past as an argument to a function.  I don't know if it is going to be a string array or a general array of strings.  I need a way to work in either case.  (Sorry for the stupid questions.  I'm just not straight with APL2 yest.)

Thanks.

Blake



 


Regards,

Daniel





reply via email to

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