1. 29
    Array languages vs. the curse of the spreadsheet apl blog.dhsdevelopments.com
    1. 6

      Was expecting this would be about how spreadsheets are secretly APLs. Like for

      Funnily enough, this is actually something that is not obvious how to do in Excel. If you have a set of numbers, and you want to add some constant to them, the way you’d do that is to create a formula that adds the constant to a cell and put that into a different location, usually on the same sheet, and then paste that formula to all the cells in an area with the same size as the original data, and hope that you got the dimensions right.

      In Excel you can actually do A1:A7+1 and it will automatically generate a column of the right shape. Or if you have it in a table, TableName[ColumnName]+1.

      I used to use J a lot for computation and last year migrated some of that over to spreadsheets. The problem with APLs is I have to think globally about the whole computation, while in Excel I can kludge it together piecemeal. Also working with strings in J was really painful. I don’t know if Kap makes the same mistakes.

      The “import from spreadsheet” stuff looks pretty cool.

      Sidenote: every time I see a new APL I feel like there’s a fundamental feature missing that nobody’s figured out yet, that’s needed to make them really work well.

      1. 5

        working with strings in J was really painful.

        String manipulation in traditional APL seems painful. A solution seen in J, APL and BQN is to use a binding to the PCRE library (with regexes represented as strings). It would be more interesting to integrate the theory of regular languages and parsers with APL array processing.

        every time I see a new APL I feel like there’s a fundamental feature missing that nobody’s figured out yet, that’s needed to make them really work well.

        APL was originally inspired by linear algebra and tensor calculus, for doing blackboard math problems and later generalized to general computing. The changes I’d make would be big ones: functions are first class values, and user defined types so that you can dispatch generic operations (including math operations) over different kinds of objects (including math objects). Then you get something like Julia, or on the Lisp side, you would get something like SCMUtils (the Scheme dialect used by Structure and Interpretation of Classical Mechanics). Or Emmy which is a Clojure port of SCMUtils. These systems are array languages that target the same mathematical domain as the original APL, but do a better job of modelling that domain, and the resulting system is much more extensible to other domains.

        These suggestions are orthogonal to having a large stock of non-ASCII operator symbols and a lack of operator precedence, which is the main thing people see when they first encounter APL.

        1. 3

          Excel array formulas and tables are very underrated. I was a proud programmer who looked down upon the Excel monkeys until I realized the folly of my pride.

        2. 5

          A visual “array editor” seems like a very useful companion to the traditional REPL experience. A few thoughts and suggestions:

          • Well-maintained workbooks typically contain named cells, named ranges, and tables; enumerating these at import time and allowing the user to choose one could be much less error prone than making a manual box-selection for large datasets. I wasn’t able to find documentation for msoffice:read, but it should also support importing ranges and tables by name if it doesn’t already.
          • Disabling the “Get” and “Set” buttons when they would have no effect (the editor state matches the REPL environment) would provide valuable feedback to the user that their action has been applied.
          • You support file drag-and-drop into the array editor already; making a drag-and-drop onto the main application window automatically open an array editor populated with data would save some clicks and drags.
          • Automatically sizing grid columns to suit the width of imported data at paste/import time would likewise save a number of interaction steps.
          1. 4

            I like the idea but it makes Perl look positively sane. It looks like line noise.

            1. 7

              You’re given a dictionary and asked to find the longest word which contains no more than 2 vowels. […]

              { ⊃ ⍵ ⊇⍨ ↑⍒≢¨ ⍵ /⍨ 2≥ (⊂"aeiou") (+/∊⍨)¨ ⍵ } io:read "dict.txt"
              

              At this point, comments suggesting the code is “unreadable” are bound to be thrown around, but once you learn a handful of symbols, this is in fact significantly more readable than the kinds of formulas I see on a regular basis in Excel.

              I have to admit I’m having difficulty imagining my myself learning that handful of symbols!

              1. 10

                Until someone asks me to stop, my Factor-translating compulsion continues . . .

                "dict.txt" utf8 file-lines
                [ >lower [ vowel? ] count 3 < ] filter
                [ length ] supremum-by
                
                1. 4

                  a more direct translation would be something like (not tested)

                  [ [ [ "aeiou" member?  ] map-sum ] map 3 < ] filter
                  [ length ] sort-by last
                  
                  1. 2

                    Thanks! I don’t know what any of the symbols mean in the original, and probably shouldn’t have called my version a “translation.”

                    But your version looks like it tries to sum booleans?

                    1. 3

                      ah, summing booleans is how APL does it. guess i need a ? 1 0 ] map-sum instead.

                  2. 4

                    Huh, this actually looks a lot nicer than the original. Do you have any personal recommendations for Factor resources?

                    1. 6

                      Someone recently posted a write up here on lobsters for a small concatenative language that looks a lot like Factor, and it does a great job explaining basics, like working with a stack.

                      I try to add good resources as posts and sidebar content to c/concatenative on lemmy, including:

                      I did a handful of Advent of Code days with it, but those may not be very good…

                      Currently I’m practicing with the Perl Weekly Challenge series.

                      1. 3

                        Wow, thanks so much!! This is super helpful, especially appreciate the link to c/concatenative and the Perl Weekly Challenges.

                        1. 2

                          those may not be very good…

                          I think it’s going to be 10,000,000,000,000 years before I can write idiomatic Factor, and I’m trying to decide whether I care.

                    2. 5

                      To my surprise ChatGPT interpreted that code and figured out what it did! https://chat.openai.com/share/b3d0dd06-d373-430d-9fe1-6898d25d56a3

                      (I gave it a link to the manual but it didn’t fetch it to read)

                      1. 2

                        Trick to make it seem easier: learn a language with a different writing system. :)

                        1. 1

                          Fortunately, the documentation is pretty solid and self-explanatory

                        2. 6

                          I like how uiua has both symbol and ascii names for each operator.

                          1. 2

                            This kind of comments is unhelpful and potentially damaging. There are billions of people who will find the sentence you wrote here look like line noise.

                            1. 4

                              damaging?

                          2. 4

                            I think there’s a lot of work to be done to spreadsheets to make them better. A saner formula editor, and maybe a better formula language would go a long way. Excel however is trapped in that a formula that was written literally in the 1980s will have to be run without issues in newer versions of Excel. Maybe bolting on Linq as an alternative is in the works, I don’t know.

                            However, allowing whitespace and comments in existing formulas would help a lot.

                            I’m not sure that APL is the solution though…

                            At this point, comments suggesting the code is “unreadable” are bound to be thrown around, but once you learn a handful of symbols, this is in fact significantly more readable than the kinds of formulas I see on a regular basis in Excel. This is proof that one is not more difficult to learn than the other, and that the problem is one of marketing rather than technological.

                            Yeah well, but asking for someone to learn a programming language where the symbols aren’t even on a keyboard is a tall ask. Most users of Excel might be doing programming in a strict sense, but like @hwayne states, it’s often “piecemeal” - “I want to search for the values matching something in this column, I know VLOOKUP is what to use, so that’s what I’ll use”, instead of realizing that this is implicitly a FOREACH loop.

                            1. 4

                              However, allowing whitespace and comments in existing formulas would help a lot.

                              Excel allows whitespace in formulas, you just have to press alt+enter for some reason.

                              1. 1

                                TIL, thanks!

                              2. 3

                                Microsoft is bolting on Python rather than Linq.

                                1. 1

                                  This doesn’t surprise me. Linq is a bit too FP for this crowd 😉

                                  1. 1

                                    While also bolting a slightly expanded excel formula syntax mostly as-is into other places: https://learn.microsoft.com/en-us/power-platform/power-fx/overview

                                  2. 1

                                    I think I would want something like a notebook, where the code and data are displayed together, but in a pure language that keeps the results up to date like a spreadsheet.

                                  3. 3

                                    BQN’s gotta be my favorite take on array languages currently. Highly suggest checking out.

                                    1. 3

                                      I have a soft spot for APL-likes and I think that it would be cool if you could write scripts/formulas for spreadsheets using one.

                                      However I have to agree with some other comments here that I think the fundamental issue with spreadsheets is not the scripting language (which itself is already essentially an APL-like, just one with uglier syntax) but their presentation of data and code.

                                      Which is to say I think that you could keep the inelegant and awkward mess that is formulas and still drastically improve the user experience of spreadsheets to solve the problems you describe.

                                      1. 2

                                        The spreadsheet paradigm hides what’s important (the formulas) in favour of the superficial (the data)

                                        It’s a single hotkey, isn’t it? Control-` or something? Covered in You suck at Excel, I think.

                                        I agree with the other stuff about types, errors (& non-errors), multi-line editing. Keeping formulas consistent always seemed like a relative non-problem, though. Working column-wise instead of cell-wise comes pretty naturally.

                                        Along those lines, it would be nice to write something like assertions on my data, matching string input through built-in parsers or regex/PEGs into usual type constructors. Then have an Errors tab, IDE-style, to work through inconsistencies.