@Razetime Ah, that's an interesting idea. We have an automatic feed of questions with the tags apl and dyalog, but there's no easy way to filter answers. There is a data explorer where one can do SQL queries, though.
@Razetime The reason that fails is because the number becomes a string with exponential notation, 3.123123E20 and then executing each character of course fails on . and E.
@Razetime Yeah, the number looses precision right away. Try setting ⎕FR←1287 first. This enables 128-bit decimal floats which have about 34 digits of precision.
For an integer, you can use 1↓0⍕X but if any digits are unknown (due to the limited precision of the currently used floats), it'll put underscores to tell you. So you can do '_'⎕R'0'⊢1↓0⍕X to replace underscores with 0s.
@TessellatingHeckler ⍬⍴ does not do what pick (first, actually) does. First unpacks the first element, while ⍬⍴ doesn't. In that sense, ⍬⍴X is exactly like X[1]. The reason I can trust ⊃ to be disclose is that the two meanings of ⊃, first and mix have the same effect on a scalar. See APL Wiki.
@TessellatingHeckler What is the shape of a scalar?
@Adám rho on a scalar returns nothing, which presumably means it returns an invisible thing which is equal to zilde, which kind of means they have no shape or a shape placeholder, and none of that suggests "reshaping an array to that non-shape should take the first element" to me
@TessellatingHeckler A scalar has 0 dimensions. You need 0 indices to pinpoint an element of a scalar. The list of lengths along all dimensions is then an empty numeric list (which is the value of ⍬). Now we know that the shape of X⍴Y is X, so if X is the shape of a scalar, then X⍴Y is a scalar filled with scalar(s) from Y. The shape of a scalar is ⍬, therefore ⍬⍴Y returns the first scalar of Y.
@Adám "so if X is the shape of a scalar, then X⍴Y is a scalar filled with scalar(s) from Y" that feels like a leap. If X is the shape of a thing with no dimensions, then X⍴Y could plausibly be the same as ⊂Y a scalar reference to Y, couldn't it?
@TessellatingHeckler No, that's not the definition of X⍴Y. it simply uses the scalars of Y in ravel order to fill an array of shape X. It never encloses anything. If it did, then 2 3⍴Y should be a matrix of Ys, rather than a matrix of Y's scalars.
The existing definition of ⍴ is more versatile. If you want an array of Ys, just write X⍴⊂Y. If X⍴Y meant that, there'd be no way to fill arrays with anything but a constant value.
@TessellatingHeckler Maybe this progression helps:
@Adám I knew you could overshape 10⍴⍳3 and it would "loop", I don't think I realised that you could undershape like 3⍴⍳10 and it would "drop" the unneeded ones
so the 1⍴1 is similar to ,1 a 1-vector, and the 1⍴Y is the first item as a 1-vector, and the step down from that is the scalar reshape which is weird; isn't it weird to describe "fill an array of shape X" when shape X is a scalar which isn't an array?
"A Sommelier Showdown Pairing Champagnes made by Nicolas Feuillatte with an array of foods will be the challenge facing sommeliers" - if that "array of foods" turned out to be one item, I think everyone in the audience would feel misled. >_>
⍬ is a valid index into a scalar. Indeed, it is the only valid index into a scalar. That it doesn't contain any information reflects on the fact that you don't need any information to know which data of a scalar you want (since there's only one).
@TessellatingHeckler (Enclosed zilde.) Indeed, ⍳ nominally returns an array of vectors, each vector representing an index. (⍳ on a one-element vector is an anomaly for historic reasons.)
@Adám the shape of a scalar is a 1-dimensional vector with no elements in it. a 1-dimensional vector with no elements in it is the only valid index into a number because numbers are arrays with no dimensions and if you go looking inside a 0-dimensional thing with an empty 1-dimensional thing, you'll find something. 😖
@TessellatingHeckler Another way to look at it is that (using ⎕IO←0) the element with index i in the array Y is the nth element of the ravel of Y where n←(⍴Y)⊥i and when ⍴Y is ⍬ and i←⍬ (the only choice) we get n←⍬⊥⍬ which is 0, and indeed, the sole element of the ravel of Y is (,Y)[0]
@Adám ok it makes sense that ⍴ can make arbitrary shaped arrays, (empty 3D array?), so 3D, 2D, 1D. And it makes sense from there that it can make 0D. And it makes sense that a 1D vector can have 3 things, 2 things, 1 thing, and next would be 0 things and that would make an empty 1D vector.
and yes ⍬≡0⍴⍳3 is 1
and it makes sense that if ⍴ can make any array, and that includes 0D, there has to be another way to distinguish that from 0⍴
@Adám no, I gotta go the other way; if 0⍴ is an empty vector, and there needs to be a different thing for a 0D array, and the left side of ⍴ is a shape, that forces a symbol which is not a number, and is the shape of a scalar, which is ⍬
[z y x]⍴ [y x]⍴ [x]⍴ []⍴ counting down the number of dimensions and needing something to go on the left of ⍴ to indicate none (although if shape and reshape were different symbols, would monadic-reshape reshape to no dimensions?)
@TessellatingHeckler Uh, []is⍬ (or 0⍴0), APL just doesn't have an array notation for it.
@TessellatingHeckler Btw, it'd be better to say "if (1⍴0)⍴ is an empty vector" since a shape is always a vector. ⍴ is just lenient and allows a scalar as stand-in for a 1-element vector.
@Adám oh I only tried 1@⊂⍬⊢0 still thinking of ⊢ as a magic separator (something dzaima (?) corrected me on recently). Parens are the syntactic separator / group.
@Razetime The safe executor won't let you. (Btw, you do realise that you don't need a leading ⋄ outside the bot, right?) It is a function contained in the dfns library workspace. You can import it with 'pco'⎕CY'dfns'