Discussion:
Odd DATATYPE Behaviour!
(too old to reply)
Chris Bruce
2009-02-07 12:16:03 UTC
Permalink
Hi there,

(Sent in RTF/HTML with Courier APL2 font so you can see session log extract)

DATATYPEþ 1 0
ý1 ý1
DATATYPEþ 1 0 2
ý2 ý2 ý2

It seems that DATATYPE is showing the wrong result!

DATATYPEþ 1 0 'A'
ý1 ý1 1
DATATYPEþ 1 0 'A' 2
ý1 ý1 1 ý2

Now showing the correct result once there's an intervening character to test. Fault also appears with real numbers...
DATATYPEþ 1 0 3.1 2
ý3 ý3 ý3 ý3
DATATYPEþ 1 0 'A' 3.1 2
ý1 ý1 1 ý3 ý3
DATATYPEþ 1 0 'A' 3.1 'B' 2
ý1 ý1 1 ý3 1 ý2

Using APL2/2 SL13 on WinXP Pro Sp2.

Chris Bruce
David Liebtag
2009-02-07 14:12:13 UTC
Permalink
Bruce,

It looks like correct results to me. If the array is entirely numeric, then
the array is stored in the simplest type that can represent the entire
array. If the array is nonhomogeneous, then each element is stored in the
simplest type than can represent that element.

David Liebtag
IBM APL Products and Services
Chris Bruce
2009-02-07 17:14:09 UTC
Permalink
Hi David,

I thought that the "each" would cause the function to treat each element in the array as a separate array, and I would have expected the second example (DATATYPEþ 1 0 2) to return ý1 ý1 ý2, and the last (DATATYPEþ 1 0 'A' 3.1 2) to return ý1 ý1 1 ý3 ý2.

Hmmmm!
David Liebtag
2009-02-09 13:53:14 UTC
Permalink
Chris,

The array's type is determined as it is constructed during the analysis of
the expression, not during execution. By the time each is called, the
array's and it's elements' types have already been established. The
interpreter does not change the type unless necessary.

David Liebtag
IBM APL Products and Services

Loading...