xpqz / learnapl

Introduction to Dyalog APL: https://xpqz.github.io/learnapl
Other
124 stars 11 forks source link

Array model wording #25

Open xpqz opened 2 years ago

xpqz commented 2 years ago

On the APL Farm matrix/discord, it was suggested that

Arrays in Dyalog APL are always collections of scalars, regardless of rank. However, we can create arbitrarily complex scalars by a process known as enclosing. This means putting something in a “box”.

is unhelpful/confusing in the long run.

@marshall suggested

A scalar like the numbers we've used above is a single value with rank 0. APL also lets you create rank 0 arrays with something inside, which also act as one unit.

@marshall

Cells (0-cells) are just one way to cut up an array. Non fundamental..

@dzaima:

In APL, everything is an array. But what about numbers? They might not look or feel like arrays, but they are. But unlike vectors, which have rank 1, or matrices, which have rank 2, etc, they have rank 0. As such, the shape of a number is ⍬. What does that entail? Do numbers contain elements..? If so, how many? What are they? Well, we can ask APL [after previously having mentioned ×/⍴x to be the number of elements]: ×/⍬ → 1. (what's that element then? Well, it's the number itself, which leads to funky recrsion, but let's not get into that). Numbers (or characters) aren't the only possible rank 0 arrays, though - you can also make your own with ⊂x - this creates a rank 0 array containing x (comparing to x y, ⊂x has one element instead of two, rank 0 instead of 1, and the previously discussed shape ⍬ instead of ,2 [ugh APL lacking a way to not properly make a 1-item list is annoying here])

ghost commented 1 year ago

"Arrays in Dyalog APL are always collections of scalars" is (imo) a helpful view for understanding the construction of nested vectors - (1 2 3)(4 5 6) is (⊂1 2 3),(⊂4 5 6) - but this is better relegated to a section on stranding.

It isn't useful for simple vectors, matrices, etc - as the 0-cells and elements of simple scalars are identical.

I would adopt Marshall's suggestion and also dive into the operational behaviour of stranding in another section.

If other topics (axes, prototypes, singletons) aren't covered a more specific and less opaque version of https://aplwiki.com/wiki/Array_model could be appropriate