3 ms·
I assume that in most array languages, you also create "words" or however you want to call functions, to reuse code. I wonder about a purely aesthetic issue: ho
by graboid 1y ago
I assume that in most array languages, you also create "words" or however you want to call functions, to reuse code. I wonder about a purely aesthetic issue: how does it look to interleave those symbols with user-defined words that by nature will be much, much longer, i.e. "create-log-entry" or "calculate-estimated-revenue".
- tailrecursion 1y agoI never did any real programming in APL, but I studied it over about 2 months. When you get used to the symbols, reading spelled-out words feels like reading in slow motion, or being stuck in molasses. Most (not all) APL code I've seen uses very short names, often one letter names, for function names. And APL programmers are famous for cataloging "idiom" which are short phrases for common subroutines. In other words, it's best practice to repeat 3- or 4- symbol phrases instead of defining a subroutine. Of course, there's nothing about an array language that requires using symbols; but for some reason most do.
- ofalkaed 1y ago>Of course, there's nothing about an array language that requires using symbols; but for some reason most do. The idioms become words and you read them like words, you don't step through each letter of a word when you read it, you recognize the shape. The same thing happens in APL and its ilk, any commonly used sequence is instantly understood as its function without having to parse each individual symbol and what it does.
- tailrecursion 1y agoYes the symbols in a way are the letters of APL, and the phrases are the words.
- kelas 1y agoin k, we say "primitive operators are verbs", and "lambdas, functions, variables, literals are nouns". higher-order functions (over, scan, each, etc) are called adverbs.
- ofalkaed 1y agoIt depends on the language and the programmer. https://github.com/mlochbaum/BQN/blob/master/vm.bqn https://github.com/mlochbaum/BQN/blob/master/vm.bqn
- kelas 1y ago> i assume that in most array languages, you also create "words" or however you want to call functions, to reuse code. sure, that's a very useful feature, like elsewhere. > I wonder about a purely aesthetic issue: how does it look to interleave those symbols with user-defined words that by nature will be much, much longer, i.e. "create-log-entry" or "calculate-estimated-revenue". strictly speaking, dashes and underscores in k can't even be a part of identifier - they are core language primitives. it is very uncommon to see java-like identifiers like CalculateEstimatedRevenue, why would you want that? to your question: here's a bit of an oddity: all user-defined functions and core language operators can be called using functional notation: v:1 2 3 / some vector v+v / usual infix notation, two operands: left and right 2 4 6 +[v;v] / same as infix, but called as it were a function. 2 4 6 add:{x+y} / a user-defined function: a lambda with a name and two operands. add[v;v] 2 4 6 but there is an important distinction between the two. you can't use your `add` function infix, you must call it as a function, and there are good reasons for that: 2 add 2 / that's not gonna work that said, mixing language primitives with function calls looks and reads just fine: +/add[v;v] 12 hope this helps!
- kbelder 1y agoHow does that scale up to program that's thousands of lines? What if you have a hundred different vectors? You're not going to be calling them v1, v2, ... So does it end up as v_sepallength: 11 14 12 v_sepallthickness: 1.3 1.5 1.2 mul[v_sepallength;v_sepalthickness] Or, do you just not do that sort of stuff in these languages? I'm not very familiar with them, but I have ended up with some pretty long programs using Pandas in Python.
- RodgerTheGreat 1y agovery important things should have short names. locals you're immediately operating upon should have short names. short names should be used in a consistent way. less important things can have longer names. variables in a broader scope can have longer names. if you have a hundred different vectors, don't just dump them in a pile; put them in dictionaries, tables, namespaces, or scopes.