It's a bit longer post, but it demonstrates that numbers are
not arrays in J.
Björn Helgason wrote:
>
> It depends on what it is
> 123 can be a number
> 123 can be text
> You can change it from text to number and other way around.
>
> So 123 can be or become what you want it to be.
>
I was talking about 123 as defined in J, where
123-as-text would be written '123'.
Henry points out that any number can be interpreted as an
array with an empty shape. Then, there is also an interpretation
that an array with an empty shape can be considered a scalar.
So, in this above case this scalar is 123, so why not call, interpret,
think of it as of a number?
> What you believe it to be may not be what it really is.
> You have to test it and make sure it is the shape and character you
> believe
> in or not.
> After you find out what 123 is you can decide on what you want to do.
> To take 123 on in blind faith can prove to be a mistake and can cause
> problems and failures.
>
If by this you mean whether I believe that the printed representation
123 of some noun tells us what the rank of the noun is, then of course
I don't believe this. For instance, if J session looks like:
f x
123
then I don't know whether the resulting 123 has rank 0 or 1,
but that's just how J prints nouns, and we can test the result
further to sort this out, as you also suggest.
So I did some testing on whether it can be distinguished in J between
123-as-number or 123-as-an-array. Basically, the issue cannot
be resolved simply by a single test: imagine that we call
all rank zero nouns that are numbers just, well, numbers.
Let's instead look how the two concepts of 123 fit into the language.
It indeed looks like 123 is an array: it has (empty) shape, rank 0,
and it has one element:
e=:0$0 NB. empty array
e -: $123
1
#123
1
0{123
123
1{123
|index error
| 1 {123
We get the index error because there is no second element of
123-as-array. So far so good. But how do we then explain
the following:
}.123
e -: }.123
1
123 -: 123,e
0
The problem with this can be stated in English as:
In J, when we drop the leading element of 123 we get
empty array, but when we append empty array to 123 we
don't get 123.
Let us just say: that is how things are defined, a bit strange
as they might be. But then again, when 123 is a one
element array, I get the desired property *of arrays*:
(1$123) -: 123,e
1
(1$123) -: 123,e,e
1
(1$123) -: 123,e,e,e,e,e,e,e
1
(1$123) -: e,e,e,123,e,e,e,e
1
(In English: appending/prepending an empty array to
an array does not change it.)
So from this follows the conclusion that 123 is not an array,
while 1$123 is.
It is not anymore the matter of interpretation of 123,
but the structural/language issue with J, namely
that numbers are not arrays, unless, that is, we drop the
requirement that appending empty array doesn't do
anything to an array.
2011/10/20 Viktor Cerovski <[email protected]>
>
>
> Raul Miller-4 wrote:
> >
> > On Thu, Oct 20, 2011 at 9:43 AM, Viktor Cerovski
> > <[email protected]> wrote:
> >> Henry Rich wrote:
> >>>
> >>> Point of nomenclature: every noun has a shape. All shapes are lists.
> >>> The shape of an atom is an empty list.
> >>>
> >>> (also, all nouns are arrays, ecch)
> >>>
> >> Statements like "all nouns are arrays" is hard to make precise
> >> due to the dynamic typing of J.
> >
> > An array is a region of computer memory whose interpretation (and, if
> > we exclude things like sparse arrays, its size) is determined by its
> > shape and its type.
> >
> > A shape is a list of non-negative integers whose product is the number
> > of elements in an array.
> >
> > To make this precise you have to enumerate those types...
> >
> Given all these conditions and definitions (a big given!),
> what is then hermeneutical horizon of 123 in J:
>
> Should I interpret it as a number, or an array, or both,
> or neither?
> --
> View this message in context:
> http://old.nabble.com/%7B.-y-produces-an-array.-tp32687373s24193p32690306.html
> Sent from the J Programming mailing list archive at Nabble.com.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Björn Helgason, Verkfræðingur
Fornustekkum II
781 Hornafirði,
t-póst: [email protected]
gsm: +3546985532
twitter: @flugfiskur
http://groups.google.com/group/J-Programming
Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
góður kennari getur stigið á tær án þess að glansinn fari af skónum
/|_ .-----------------------------------.
,' .\ / | Með léttri lund verður |
,--' _,' | Dagurinn í dag |
/ / | Enn betri en gærdagurinn |
( -. | `-----------------------------------'
| ) | (\_ _/)
(`-. '--.) (='.'=) ♖♘♗♕♔♙
`. )----' (")_(") ☃☠
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
View this message in context:
http://old.nabble.com/%7B.-y-produces-an-array.-tp32687373s24193p32691792.html
Sent from the J Programming mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm