I just started learning APL a couple of weeks ago, so this may sound like a newbie question.
Let B
be a string, which in APL terms can be either a scalor or a vector. If it's a scalar, ⍴B
returns null rather than the length of the string as I want.
B←'QR'
⍴B ⍝ returns 2
B←'Q'
⍴B ⍝ returns null
I discovered one way around that:
⍴1↓'X',B ⍝ concatenating X and then removing it returns a value of 1
That works, but it seems a little hokey, so I'm wondering if there is a more standard way to find string length.
Is it just me or does this seem a little inconsistent? The tutorial I read said to think of a scalar as a point similar to the way it is in vector algebra. But how is it that concatenating a scalar to a scalar makes a vector, but dropping a scalar from a vector never results in a scalar?
I'm really enjoying APL, so this question isn't meant as criticism. My question is, what's the best way to find string length? And, if anyone can shed a little light on this seeming inconsistency, it would be appreciated.