Discussion:
[Bug-apl] scalar/array
e***@gmx.com
2017-03-03 17:29:03 UTC
Permalink
i just watched a great video on apl and this was discussed i still don't know what the harm/problem would be if instead of returning 'nothing'

⍴'a' why doesn't it return 1 - there is something there please don't mention scalar i know all about it - but to me this has always been an inconsistency in apl that made no sense to me

⍴'aa' the , isn't required in ⍴,'aa' to be consistent ??
2
⍴,'a'
1


'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a



under what condition would 'a'[1] returning 'a' be a problem?
Elias Mårtenson
2017-03-03 17:37:18 UTC
Permalink
In GNU APL, try this instead :

"a"[1]

The reason this seems inconsistent is because single quote is used to
define a string, i.e. an array of characters. Except the case where there
is only a single character, in which case it represents a scalar
character.

GNU APL allows you to use double quote instead which doesn't have this
inconsistency.

That should make things a bit more clear, I hope.

Regards,
Elias
Post by e***@gmx.com
i just watched a great video on apl and this was discussed i still
don't know what the harm/problem would be if instead of returning 'nothing'
⍎'a' why doesn't it return 1 - there is something
there please don't mention scalar i know all about it - but to me this
has always been an inconsistency in apl that made no sense to me
⍎'aa' the , isn't required in ⍎,'aa' to be
consistent ??
2
⍎,'a'
1
'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a
under what condition would 'a'[1] returning 'a' be a problem?
e***@gmx.com
2017-03-03 17:57:36 UTC
Permalink
thank you - fantastic ...it sure 'fixes' the inconsistency i had no idea about "a"

I saw the use of " only in the FILE_IO "r" in the apl.html but thought that was related to just fopen/bash/c syntax

---

Do you know the 'details' about why iverson did this to begin with?

How did you deal with scalar 'a' before the "a" in gnuap?

didn't you have 'wasted code' to deal with the following to deal with scalar 'a'

⍴'a'

''=⍴'a'

⍴⍴'a'
0

---

the video in case you hadn't seen it

# APL 1991 Conference.mpg 1 hour, 50 minutes


---

On Sat, 4 Mar 2017 01:37:18 +0800
Post by Elias MÃ¥rtenson
"a"[1]
The reason this seems inconsistent is because single quote is used to
define a string, i.e. an array of characters. Except the case where there
is only a single character, in which case it represents a scalar
character.
GNU APL allows you to use double quote instead which doesn't have this
inconsistency.
That should make things a bit more clear, I hope.
Regards,
Elias
Post by e***@gmx.com
i just watched a great video on apl and this was discussed i still
don't know what the harm/problem would be if instead of returning 'nothing'
⍴'a' why doesn't it return 1 - there is something
there please don't mention scalar i know all about it - but to me this
has always been an inconsistency in apl that made no sense to me
⍴'aa' the , isn't required in ⍴,'aa' to be consistent ??
2
⍴,'a'
1
'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a
under what condition would 'a'[1] returning 'a' be a problem?
Juergen Sauermann
2017-03-03 19:45:45 UTC
Permalink
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font face="Helvetica, Arial, sans-serif">Hi,<br>
<br>
I believe the reason why<font face="Courier New, Courier,
monospace"><b> 'a' </b></font>is scalar and <font
face="Courier New, Courier, monospace"><b>'abc'</b></font> is
not is the same as why <font face="Courier New, Courier,
monospace"><b>1</b></font> is a scalar and <font face="Courier
New, Courier, monospace"><b>1 2 3</b> </font>is not.<br>
<br>
It is very consistent, but often very inconvenient. And in
practice it is often a pitfall for the unaware programmer.<br>
I fooled myself a couple of times and then decided to introduce <font
face="Courier New, Courier, monospace"><b>"a"</b></font> which
avoids the problems with <font face="Courier New, Courier,
monospace"><b>'a'</b></font>.<br>
<br>
Before <font face="Courier New, Courier, monospace"><b>"a"</b></font>
you had to <font face="Courier New, Courier, monospace"><b>(,'a')</b></font>
or <font face="Courier New, Courier, monospace">,'a'</font> if
circumstances allowed (introducing other traps, of course).<br>
<br>
/// Jürgen<br>
<br>
</font><br>
<div class="moz-cite-prefix">On 03/03/2017 06:57 PM, <a class="moz-txt-link-abbreviated" href="mailto:***@gmx.com">***@gmx.com</a>
wrote:<br>
</div>
<blockquote cite="mid:***@gmx.com"
type="cite">
<pre wrap="">thank you - fantastic ...it sure 'fixes' the inconsistency i had no idea about "a"

I saw the use of " only in the FILE_IO "r" in the apl.html but thought that was related to just fopen/bash/c syntax

---

Do you know the 'details' about why iverson did this to begin with?

How did you deal with scalar 'a' before the "a" in gnuap?

didn't you have 'wasted code' to deal with the following to deal with scalar 'a'

⍴'a'

''=⍴'a'

⍴⍴'a'
0

---

the video in case you hadn't seen it

# APL 1991 Conference.mpg 1 hour, 50 minutes
<a class="moz-txt-link-freetext" http://youtu.be/uZOZYYPmUnM

---

On Sat, 4 Mar 2017 01:37:18 +0800
Elias Mårtenson <a class="moz-txt-link-rfc2396E" href="mailto:***@gmail.com">&lt;***@gmail.com&gt;</a> wrote:

</pre>
<blockquote type="cite">
<pre wrap="">In GNU APL, try this instead :

"a"[1]

The reason this seems inconsistent is because single quote is used to
define a string, i.e. an array of characters. Except the case where there
is only a single character, in which case it represents a scalar
character.

GNU APL allows you to use double quote instead which doesn't have this
inconsistency.

That should make things a bit more clear, I hope.

Regards,
Elias

On 4 Mar 2017 01:29, <a class="moz-txt-link-rfc2396E" href="mailto:***@gmx.com">&lt;***@gmx.com&gt;</a> wrote:

</pre>
<blockquote type="cite">
<pre wrap="">
i just watched a great video on apl and this was discussed i still
don't know what the harm/problem would be if instead of returning 'nothing'

⍴'a' why doesn't it return 1 - there is something
there please don't mention scalar i know all about it - but to me this
has always been an inconsistency in apl that made no sense to me

⍴'aa' the , isn't required in ⍴,'aa' to be
consistent ??
2
⍴,'a'
1


'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a



under what condition would 'a'[1] returning 'a' be a problem?


</pre>
</blockquote>
</blockquote>
<pre wrap="">

</pre>
</blockquote>
<br>
</body>
</html>
e***@gmx.com
2017-03-03 21:57:00 UTC
Permalink
On Fri, 3 Mar 2017 20:45:45 +0100
Hi,
what is the reason? do you know their reasoning

cause 1 is 1 element and 1 2 3 is 3 elements so ⍴ 1 2 3 is 3 and ⍴ 1 should have been 1

I never understood their reasoning or how it negatively affected anything else - it must have been in the implementation that they had couldn't apply vector/array code to just one element so they did it this way
i think like the char type vs array type but you can have an array of 1 element (in c and fpc anyway)
I believe the reason why 'a' is scalar and 'abc' is not is the same as why 1 is a scalar and 1 2 3 is not.
It is very consistent, but often very inconvenient. And in practice it is often a pitfall for the unaware programmer.
I fooled myself a couple of times and then decided to introduce "a" which avoids the problems with 'a'.
Before "a" you had to (,'a') or ,'a' if circumstances allowed (introducing other traps, of course).
/// Jürgen
thank you - fantastic ...it sure 'fixes' the inconsistency i had no idea about "a"
I saw the use of " only in the FILE_IO "r" in the apl.html but thought that was related to just fopen/bash/c syntax
---
Do you know the 'details' about why iverson did this to begin with?
How did you deal with scalar 'a' before the "a" in gnuap?
didn't you have 'wasted code' to deal with the following to deal with scalar 'a'
⍴'a'
''=⍴'a'
⍴⍴'a'
0
---
the video in case you hadn't seen it
# APL 1991 Conference.mpg 1 hour, 50 minutes
http://youtu.be/uZOZYYPmUnM
---
On Sat, 4 Mar 2017 01:37:18 +0800
"a"[1]
The reason this seems inconsistent is because single quote is used to
define a string, i.e. an array of characters. Except the case where there
is only a single character, in which case it represents a scalar
character.
GNU APL allows you to use double quote instead which doesn't have this
inconsistency.
That should make things a bit more clear, I hope.
Regards,
Elias
i just watched a great video on apl and this was discussed i still
don't know what the harm/problem would be if instead of returning 'nothing'
⍴'a' why doesn't it return 1 - there is something
there please don't mention scalar i know all about it - but to me this
has always been an inconsistency in apl that made no sense to me
⍴'aa' the , isn't required in ⍴,'aa' to be consistent ??
2
⍴,'a'
1
'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a
under what condition would 'a'[1] returning 'a' be a problem?
Elias Mårtenson
2017-03-04 10:36:27 UTC
Permalink
On 4 March 2017 at 05:57, <***@gmx.com> wrote:

what is the reason? do you know their reasoning
cause 1 is 1 element and 1 2 3 is 3 elements so ⍎ 1 2 3 is 3
and ⍎ 1 should have been 1
But that's wrong. 1 is not a one-element array. 1 is just a number. 1 2 is
a two-element array. Each element being a number.

The fact that 1 is interpreted as a number, as opposed to a single-element
array is just an artifact of the language. One could easily modify the APL
parser to yield such result, but it wouldn't be very useful in most cases.

I guess that by now you're wondering why even have the concept of a scalar?
Why not make numbers being a one-dimensional array with size 1? Well, for
some operations, behaviour would remain the same, but there are situations
you definitely want to be able to tell "a single number" (i.e. a scalar)
vs. "an array". For example, A=B behaves differently depending on whether A
is a single-element array or a scalar value.

Note that this beahviour isn't limited to APL. Lisp also has a concept of
zero-dimensional arrays (although it doesn't take it as far as APL in that
numbers and zero-dimensional arrays still have different types). From the
Hyperspec <http://clhs.lisp.se/Body/15_aac.htm>:

*If the rank of an array <http://clhs.lisp.se/Body/26_glo_a.htm#array> is
zero then the array <http://clhs.lisp.se/Body/26_glo_a.htm#array> is said
to have no dimensions <http://clhs.lisp.se/Body/26_glo_d.htm#dimension>,
and the product of the dimensions (see array-total-size
<http://clhs.lisp.se/Body/f_ar_tot.htm#array-total-size>) is then 1; a
zero-rank array <http://clhs.lisp.se/Body/26_glo_a.htm#array> therefore has
a single element.*


Finally, the idea of scalars being zero-dimensional arrays makes sense from
a maths standpoint as well:

https://math.stackexchange.com/questions/664594/why-mathbf0-vector-has-dimension-zero
https://en.wikipedia.org/wiki/Dimension_(vector_space)

Regards,
Elias
Juergen Sauermann
2017-03-04 11:13:48 UTC
Permalink
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font face="Helvetica, Arial, sans-serif">Hi,<br>
<br>
the scalar extension mechanism is a very fundamental principle
which existed since<br>
the beginning of APL. If you randomly pick an 1-element value from
any APL program,<br>
then I would bet that the value is a scalar with a probability of
≥ 90%, and a matrix or<br>
higher rank value with a probability of ≤ 1%. There have been
studies about this in<br>
the 1980s.<br>
<br>
Therefore taking a 1-element item as a scalar is simply the most
pragmatic choice.<br>
<br>
/// Jürgen<br>
<br>
</font><br>
<div class="moz-cite-prefix">On 03/03/2017 10:57 PM, <a class="moz-txt-link-abbreviated" href="mailto:***@gmx.com">***@gmx.com</a>
wrote:<br>
</div>
<blockquote cite="mid:***@gmx.com"
type="cite">
<pre wrap="">On Fri, 3 Mar 2017 20:45:45 +0100
Juergen Sauermann <a class="moz-txt-link-rfc2396E" href="mailto:***@t-online.de">&lt;***@t-online.de&gt;</a> wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Hi,

</pre>
</blockquote>
<pre wrap="">
what is the reason? do you know their reasoning

cause 1 is 1 element and 1 2 3 is 3 elements so ⍴ 1 2 3 is 3 and ⍴ 1 should have been 1

I never understood their reasoning or how it negatively affected anything else - it must have been in the implementation that they had couldn't apply vector/array code to just one element so they did it this way
i think like the char type vs array type but you can have an array of 1 element (in c and fpc anyway)


</pre>
<blockquote type="cite">
<pre wrap="">I believe the reason why 'a' is scalar and 'abc' is not is the same as why 1 is a scalar and 1 2 3 is not.

It is very consistent, but often very inconvenient. And in practice it is often a pitfall for the unaware programmer.
I fooled myself a couple of times and then decided to introduce "a" which avoids the problems with 'a'.

Before "a" you had to (,'a') or ,'a' if circumstances allowed (introducing other traps, of course).

/// Jürgen


On 03/03/2017 06:57 PM, <a class="moz-txt-link-abbreviated" href="mailto:***@gmx.com">***@gmx.com</a> wrote:
thank you - fantastic ...it sure 'fixes' the inconsistency i had no idea about "a"

I saw the use of " only in the FILE_IO "r" in the apl.html but thought that was related to just fopen/bash/c syntax

---

Do you know the 'details' about why iverson did this to begin with?

How did you deal with scalar 'a' before the "a" in gnuap?

didn't you have 'wasted code' to deal with the following to deal with scalar 'a'

⍴'a'

''=⍴'a'

⍴⍴'a'
0

---

the video in case you hadn't seen it

# APL 1991 Conference.mpg 1 hour, 50 minutes
<a class="moz-txt-link-freetext" http://youtu.be/uZOZYYPmUnM

---

On Sat, 4 Mar 2017 01:37:18 +0800
Elias Mårtenson <a class="moz-txt-link-rfc2396E" href="mailto:***@gmail.com">&lt;***@gmail.com&gt;</a> wrote:

In GNU APL, try this instead :

"a"[1]

The reason this seems inconsistent is because single quote is used to
define a string, i.e. an array of characters. Except the case where there
is only a single character, in which case it represents a scalar
character.

GNU APL allows you to use double quote instead which doesn't have this
inconsistency.

That should make things a bit more clear, I hope.

Regards,
Elias

On 4 Mar 2017 01:29, <a class="moz-txt-link-rfc2396E" href="mailto:***@gmx.com">&lt;***@gmx.com&gt;</a> wrote:


i just watched a great video on apl and this was discussed i still
don't know what the harm/problem would be if instead of returning 'nothing'

⍴'a' why doesn't it return 1 - there is something
there please don't mention scalar i know all about it - but to me this
has always been an inconsistency in apl that made no sense to me

⍴'aa' the , isn't required in ⍴,'aa' to be
consistent ??
2
⍴,'a'
1


'a'[1]
RANK ERROR
'a'[1]
^ ^
'ab'[1]
a
(,'a')[1]
a



under what condition would 'a'[1] returning 'a' be a problem?





</pre>
</blockquote>
<pre wrap="">

</pre>
</blockquote>
<br>
</body>
</html>
Kacper Gutowski
2017-03-04 16:39:49 UTC
Permalink
Post by e***@gmx.com
cause 1 is 1 element and 1 2 3 is 3 elements so ⍴ 1 2 3 is 3 and ⍴ 1 should have been 1
But 1-element arrays come in many different shapes and ⍴ returns the shape
rather than number of elements. To get the later you would use ×/⍴ and ×/⍴1
is indeed 1 but so is ×/⍴(1 1 1 1⍴1).

As for the syntax, it's not exactly accurate and doesn't apply to character
vectors but I find it convenient to assume that bare number is always a scalar.
Consider that in APL2 you can create vectors by juxtaposing values:

A←1
B←2
1 2 ≡ A B
1

So we can pretend there is no special syntax for numeric vector literals at
all. It doesn't translate well to character vectors but I consider 'aa' to
be a syntactic sugar for 'a' 'a'.

I don't know the original reasoning behind it but I think it's the most natural
to have bare number literal stand for the most basic kind of value that exists
in a language. As long as we want to have 0-rank arrays (and we do!), forcing
one to write something like ↑1 to get a scalar would be weird and I prefer
having to write ,1 for vector instead.

-k

Loading...