The behaviour that you see is caused by an inconsistency in the APL syntax. A sequence of characters enclosed in single-quotes creates an array of those characters. For example, 'foo'
creates an array of the characters f
, o
and o
. Calling ⍴
on this array shows the expected result:
⍴'foo'
3
However, these is an exception to this rule, and this is where the syntax is inconsistent. When you specify a single character inside the single quotes, you do not create an array of a single character, but rather the character itself is returned. This is why ⍴'f'
returns an empty array, since the value is a scalar.
As was suggested by Pé de Leão, you can use the ,
function to ensure that a scalar value becomes an array which is why using ⍴,
works regardless of whether its argument is a scalar or an array.
Because of this inconsistency, GNU APL has an extension that allows you to use "
instead of '
when typing strings. The only difference between them is that "
always creates an array, even for single characters.