Readit News logoReadit News
lokedhs commented on An imperative introduction to array programming   blog.dhsdevelopments.com/... · Posted by u/lokedhs
ofalkaed · a year ago
Never heard of Kap before, I find the use of APL symbols and left to right parsing very difficult to read, my brain immediately starts reading right to left when I see APL symbols. I think Kap kills a lot of the elegance of APL as well but maybe I will feel better about it after I get a bit further along in APL, just started learning it a couple weeks ago and at my level of APL, Kap is very confusing to read.
lokedhs · a year ago
Interesting observation. The fundamental syntax of Kap is the same as APL. The imperative style is added on top, and isn't really the way you'd normally write code. The examples were written that way in order to make a point the the code can he as verbose as you want.

I often use the code from the standard library that renders array output as an example of real world Kap code that is written in what I would consider regular style.

https://codeberg.org/loke/array/src/branch/master/array/stan...

lokedhs commented on Arthur Whitney's one liner sudoku solver (2011)   dfns.dyalog.com/n_sudoku.... · Posted by u/secwang
upghost · a year ago
I am kind of curious if you have to mentally keep track of the rank/shape/dimensions in your head or if there is some implicit/explicit convention for conveying that to the reader. Does tracking rank/shape become second nature after awhile?

I'm also wondering about things like (APL-style) inner products -- they are undeniably powerful, but it's hard for me to conceptual use cases above rank 3.

lokedhs · a year ago
That depends on the specific code. Some code is written to be agnostic to the rank, while others make certain assumptions.

In my code I'd sometimes write assertions in the beginning of a function to not only ensure it's called with the right shape but also as documentation.

Also, in practice really high rank arrays aren't used much. Even 4 is pretty rare.

lokedhs commented on Arthur Whitney's one liner sudoku solver (2011)   dfns.dyalog.com/n_sudoku.... · Posted by u/secwang
Duanemclemore · a year ago
For me one of the most important things here is the clarity of the problem -maker- at the top. That's the difference between the "Iversonian" symbolic languages (J and K included) and others. It doesn't have the elegance and power of a one line solution, but it's just so clean and comprehensible even without the disciplined commenting. (Although I really think lamp is not a good comment glyph. Sorry about the sacred cow I just took a swipe at fellow array nerds.)

One line solutions are incredible, and tacit is mind-bendingly cool. To use the unique compactness of a glyph-based language as a way to efficiently describe and perform functional programming - then to do that all over arrays!? - whoever had these ideas [0] is utterly genius.

But as someone trying to make time to write a program ground up in APL, knowing that I won't be able to make it just a set of really good one liners, that example is also significant for me.

[0] https://www.jsoftware.com/papers/fork.htm

lokedhs · a year ago
Just because you can write everything on one line without any spaces doesn't mean you should.

You can ofcourse removethe capability to do thatand you'll effectively force the programmer to write more venous code, but then its strength as an interfacing tool is very much reduced.

The Iversonian languages has the capability to write incredibly terse code which is really useful when working interactively. When you do, your code truly is write-only because it isn't even saved. This is the majority of code that at least I write in these languages.

When writing code that goes in a file, you can choose which style you want to use, and I certainly recommend making it a bit less terse in those cases. The Iversonian languages are still going to give you organs that are much shorter than most other languages even even it's written in a verbose style.

lokedhs commented on Arthur Whitney's one liner sudoku solver (2011)   dfns.dyalog.com/n_sudoku.... · Posted by u/secwang
upghost · a year ago
Very nice! I like the readability-- not sure if thats just indicative of your style or the language, and the map construct is also nice. I don't remember any off-the-shelf map construct, at least not in Dyalog.
lokedhs · a year ago
It's likely a combination of both. It's certainly possible to write Kap in a much more condensed form. But things like if-statements and hash maps does allow for a more imperative style.
lokedhs commented on Arthur Whitney's one liner sudoku solver (2011)   dfns.dyalog.com/n_sudoku.... · Posted by u/secwang
upghost · a year ago
Most people are put off by the symbols, that wasn't really the issue I had.

So I do love APL and arraylangs, and learning them was really helpful in a lot of other languages.

But they never became a daily driver for me not because of the symbols, which were honestly fine if you stick with it long enough, but after about 3-4 years of dabbling on and off I hit a wall with APL I just couldn't get past.

Most other languages I know there is a "generic-ish" approach to solving most problems, even if you have to cludge your way through suboptimally until you find "the trick" for that particular problem and then you can write something really elegant and efficient.

APL it felt like there was no cludge option -- you either knew the trick or you didn't. There was no "graceful degredation" strategy I could identify.

Now, is this actually the case? I can't tell if this is a case of "yeah, thats how it is, but if you learn enough tricks you develop an emergent problem solving intuition", or if its like, "no its tricks all the way down", or if its more like, "wait you didn't read the thing on THE strategy??".

Orrr maybe I just don't have the neurons for it, not sure. Not ruling it out.

lokedhs · a year ago
You're not wrong. It's very easy to get that impression when trying to learn the array languages. It's very easy for someone who's used these languages for a long time to look at a problem, and say "why did you use that really elaborate solution, when you can just use ⍸⍣¯1?". No one probably ever told you that ⍸ has an inverse, and how you could use it.

Even today, after having worked in these languages for years, I am still put off a bit by the walls of code that some array programmers produce. I fully understand the reasoning why it's written like that, but I just prefer a few spaces in my code.

I've been working on an array language based on APL, and one of my original goals was to make "imperative style" programming more of a first-class citizen and not punish the beginner from using things like if-statements. It remains to be seen how well I succeeded, but even I tend to use a more expressive style when terseness doesn't matter.

Here's an example of code I've written which is the part of the implementation that is responsible for taking any value (such as nested arrays) and format them nicely as text using box drawing characters. I want to say that this style is a middle ground between the hardcore pure APL style found in some projects and the style you'll see in most imperative languages: https://codeberg.org/loke/array/src/branch/master/array/stan...

lokedhs commented on Arthur Whitney's one liner sudoku solver (2011)   dfns.dyalog.com/n_sudoku.... · Posted by u/secwang
shahbazac · a year ago
I’ve often wondered about languages like APL/k, are the programmers actually able to think about problems more efficiently?
lokedhs · a year ago
"More efficiently"? Maybe. It opens up a new way to think about solutions to problems. Sometimes those solutions are more efficient, and sometimes they are just different.

It's a useful thing to learn though. And dare I say it, fun. Even if there was zero benefit to it, it'd still be fun. As it turns out, there really are benefits.

For me, the biggest benefit is when I'm working with data interactively. The syntax allows me to do a lot of complex operations on sets of data with only a few characters, which makes you feel like you have a superpower (especially when comparing to someone using Excel to try to do the same thing).

lokedhs commented on A List of companies that use Array Languages (J, K, APL, q)   github.com/interregna/arr... · Posted by u/tosh
mxz3000 · a year ago
For the experts in this thread: is there any benefit to using these so called array languages compared to using something like numpy (or even pandas/polars) ?
lokedhs · a year ago
The short answer is yes. There have been many presentations on this topic that tries to explain it in various ways.

The problem is that most people who are unfamiliar with APL usually don't see the larger picture, and you need to learn the language before understanding the reasoning. But once you understand it, you don't really need to hear the arguments anymore.

One argument that may be easier to digest is that the very optimised syntax allows you to easily work with the data in an interactive fashion. This is similar to how a calculator that forced you to write 1.add(2) would be rather painful to use, even if it functionally is the same as 1+2.

In programs that you save to a file and is part of a larger project, this benefit is of course less relevant.

lokedhs commented on Array languages vs. the curse of the spreadsheet   blog.dhsdevelopments.com/... · Posted by u/PaulHoule
amluto · 2 years ago
Now I know what that particular symbol means! Except that it looks kind of like a down arrow, and that link suggests it’s Grade Down.

Would writing argsort(name_of_array, reverse=True) really be so much worse? Or argsort[reverse] (made up syntax) if you want a point-free function form?

lokedhs · 2 years ago
It's not sort. In Kap, sort down is ∨. The grade functions returns a sorted index. Basically ⍒ 3 1 2 1 1 returns 0 2 1 3 4. So yes, it performs a sort, but it returns an index that can be used to later look up the respective elements.

You can read more about it here if you're interested: https://www.aplwiki.com/wiki/Grade

And here's a silly example where a random array is created, then an array lookup is performed on the sorted indexes:

https://kapdemo.dhsdevelopments.com/clientweb2/#a%20%E2%86%9...

u/lokedhs

KarmaCake day2897March 5, 2011View Original