4 ms·
In APL, everything is an array, and everything is designed to operate on an array. So ⎕ ← 1 + 2 will yield 3, and ⎕ ← 1 9 5 + 2 will yield 3 11 7. O
by ktRolster 10y ago
In APL, everything is an array, and everything is designed to operate on an array. So
⎕ ← 1 + 2
will yield 3, and
⎕ ← 1 9 5 + 2
will yield 3 11 7. Of course, you can have complex arrays as well: (2 3) (5 4 2) in APL will be an array with two elements: the first element having two sub-elements, and the second having three sub-elements. The question then, is what about (2)? Should that be an array inside an array? Or just an array? That is my understanding of that paragraph.
I don't think the question of "which is best" here can be answered without a lot of practical experience trying both methods. If you like APL, I think this is a good tutorial: http://www.zerobugsandprogramfaster.net/essays/5b.html http://www.zerobugsandprogramfaster.net/essays/5b.html
- throwaway7645 10y agoThere is also an interactive try APL website by the folks at Dyalog I believe. At least they link to it. Dyalog also has a free Mastering Dyalog APL book that although implementation specific is general enough. J is a similar free & open source APL-like language with several tutorials.
- lokedhs 10y agoIn original APL, there was only arrays, and inside each cell in an array you could put scalars. A scalar was simply a number or a character. A string is a single-dimensional array of characters, which is quite logical. Now, with this design, how do you manage a collection of strings? Turns out you can't, so what old software used to do was so have a two-dimensional array of characters. This works reasonably well, except that this means that all strings have to be the same length. You can work with this, but can be very annoying. What APL2 introduced was the idea that you can not only put scalars inside an array, but also other arrays. This is of course how pretty much every other programming language works, but at the time (as far as I know, this is way before my time) this was seen as very controversial since it made the language less clean, or "elegant". To go into some details, you can consider a scalar as an array of dimension zero: ⍴⍴5 0 (⍴⍴ returns the dimension of the argument to the right[1]) Once you have nested arrays, you can also wrap an array inside a scalar. This allows you to more easily treat arrays as single objects: s ← 'hello' ⍝ Assign the string "hello" to s ⍴⍴s ⍝ Confirm that s is a one-dimensional array 1 s2 ← ⊂s ⍝ The ⊂ wraps its argument as a scalar, assign the result to s2 ⍴⍴s2 ⍝ The result now has 0 dimensions 0 [1] To go really deep into the technical details, it returns the dimensions of the dimensions of the argument. A scalar has no dimensions, do ⍴5 returns an empty array. The second ⍴ returns zero because an empty array has zero elements.
- gtani 10y agoThanks. My APL2 used to be littered with a lot of "eaches" which generated a lot of complaints in code review (raised, "sideways colon"), but seemed a natural way to express things. Is this a divergence between APL2 and Sharp implementation? I used to work (a long time ago) with a lot of ex-Sharp people from Toronto who were always harping about the superiority of Sharp.
- lokedhs 10y agoI'm not sure. I don't actually know that much amount APL history. I've really only used it for a few years. If you want a lot more information about that, I recommend you join the GNU APL mailing list, as some of the members there know a lot about the history: https://lists.gnu.org/mailman/listinfo/bug-apl https://lists.gnu.org/mailman/listinfo/bug-apl As far as I know, Sharp APL was "old style" in the sense that it did not support nested arrays. Some people may like that style, but I have a hard time seeing that it is "better", since the nesed arrays are backward compatible with the non-nested style. Note that you can also use the ⊂ and ⊃ functions to convert between nested and recursive arrays. For example, assuming you have an array of strings: a ← 'here' 'are' 'some' 'strings' ⍝ a is now a single-dimensional array of 4 elements ⍴a 4 ⍝ The ⊃ function converts the nested array into a two-dimensional array ⊃a here are some strings ⍝ The array is two-dimensional with 4 rows and 7 columns ⍴ ⊃a 4 7
- beagle3 10y agoThe K programming language (as implemented in kparc, kdb+, kona and oK), an cousin of APL, does away with explicit matrices, and has 3 basic types: atom=scalar, list=vector and dict=mapping. A 2d matrix is implemented as a vector of (vectors of all the same dimensions); a 3d matrix is implemented as a vector of (matrices all of the same dimensions). This greatly simplified the entire language - both semantics and implementation.