Earlier quoted context omitted.
Aaron Hsu writes about this a lot. In an APL snippet, you often don't need layers of blackbox abstractions. You can see the whole thing at a macro layer. I'm sure it takes time though.
Layers of abstractions are useful though, they allow you to concentrate on what matters for the code in question.
Stages of denial in encountering K
361–370 of 432 posts
Re: Stages of denial in encountering K
#362I have the same question for K aficionados as I have for Forth ones: what real-world, human-usable, important software has been written in it? A GUI framework, a web browser, a window manager, a text editor, etc. Anything? I'm asking because the article is poking at C-like languages, i.e. implying that K is good for general-purpose use. Yet all I hear about is that K is good at multiplying numbers and matrices, which…
Re: Stages of denial in encountering K
#363Earlier quoted context omitted.
Performance depending on your use case. APL/J/K can be very fast for an interpreted language, but they won't beat C, C++, Fortran, and Java in most cases. Also, think about distribution. With most of the array languages, it is commercial, so I'd be cautious about building a business around it. With other languages, it is free to use and deploy as you see fit and some have binary executables that don't need a runtime.…
> With most of the array languages, it is commercial, so I'd be cautious about building a business around it K/Kdb/q seems very happy with this state of affairs, which is really strange: if they O/S'd it I could see a lot of goodwill/mindshare going their way, but I think their Morgan Stanley roots view O/S as commie nonsense. Meanwhile, it's definitely viewed as legacy in the bulge-bracket banks that use it b/c it's…
Re: Stages of denial in encountering K
#364Look, I don't hate K. It's probably a pretty good language for the task it seems to have been designed for, which appears to be numerical computing. Being able to fit an entire code on a screen is an interesting concept; while I'm not completely convinced it should be a goal in and of itself it's certainly something I can't rule out as a possible productivity booster. However, I still find it problematic, and it's no…
I love small languages (lisps, forths, apls) and think that there is much to learn from them, but you need an open mind. You need to start from zero and totally forget your ALGOL-mindset while you are learning the new paradigm. It's like learning Chinese. Everyone learns it in China, and everyone there will tell you that it's perfectly readable and you don't need to be extraordinarily intelligent to speak it. But if…
Microsoft's sample application "Your First Windows Program", written in C, using Win32 calls, can be translated into TXR Lisp literally, almost expression for expression:
https://docs.microsoft.com/en-us/windows/win32/learnwin32/yo...
The "meat" part, without the FFI declarations that precede it:
(defun WindowProc (hwnd uMsg wParam lParam)
(caseql* uMsg
(WM_DESTROY
(PostQuitMessage 0)
0)
(WM_PAINT
(let* ((ps (new PAINTSTRUCT))
(hdc (BeginPaint hwnd ps)))
(FillRect hdc ps.rcPaint (cptr-int (succ COLOR_WINDOW) 'HBRUSH))
(EndPaint hwnd ps)
0))
(t (DefWindowProc hwnd uMsg wParam lParam))))
(let* ((hInstance (GetModuleHandle nil))
(wc (new WNDCLASS
lpfnWndProc [wndproc-fn WindowProc]
hInstance hInstance
lpszClassName "Sample Window Class")))
(RegisterClass wc)
(let ((hwnd (CreateWindowEx 0 wc.lpszClassName "Learn to Program Windows"
WS_OVERLAPPEDWINDOW
CW_USEDEFAULT CW_USEDEFAULT
CW_USEDEFAULT CW_USEDEFAULT
NULL NULL hInstance NULL)))
(unless (equal hwnd NULL)
(ShowWindow hwnd SW_SHOWDEFAULT)
(let ((msg (new MSG)))
(while (GetMessage msg NULL 0 0)
(TranslateMessage msg)
(DispatchMessage msg))))))
Full code here: https://www.nongnu.org/txr/rosetta-solutions-main.html#Windo...If you look at this and the C side by side, you can easily see where the parts match up.
Re: Stages of denial in encountering K
#365Earlier quoted context omitted.
> Unless everybody is born learning a language, no we don't. Even 'The one they use the most' varies over time. Nobody is born having learned a language. It's something even babies have to learn and they know nothing! People can even "switch" their native spoken language up to a point although it seems to get much harder as they get older and more experienced with one language, as they're constantly comparing their a…
> Nobody is born having learned a language. It's something even babies have to learn and they know nothing! I meant a programming language (it gets confusing, sorry). But anyways, our native language is much more embedded in the brain than programming languages. > I think if you decided to write your "simple script" in even a well-known language like JavaScript, you'd cause some grumbles in a Python+C# shop; k isn't…
I think it's possible that might have more to do with the fact we use "our native language" more.
> Yes. And I'd cause even more grumbles if it was written in Haskell, and even more if it was on K. That's the point.
I don't know. I work in a place with a lot of q/k programmers, so this isn't a problem I face.
> Yes, and that changes how you access the data. So the evaluation was not fair, as the OP was not using sorted data.
You're mistaken. They did use sorted data, they just didn't know about the presorted file so they also wrote code to sort it.
> is 100b a value or a vector?
It's a vector of three elements (bits: zeros or ones).
> What if "f:42 1 2"? f=42 returns 100b … so under the common "and" definition "(f=42)&(g=69)" should return 000b
Yes that's right, and q/k would return 000b in that case.
> under the "less than" returns 010b?
100b
f g k
--------
10 9 kf
20 8 je
42 69 kf
42 0 lk
That's written like this: t:+`f`g`k!(10 20 42 42;9 8 69 0;`kf`je`kf`lk);
k has tables as a data type. You can think of them as a list of dictionaries if you want: q)a:`f`g`k!(10;9;`kf);
q)b:`f`g`k!(20;8;`je);
q)c:`f`g`k!(42;69;`kf);
q)d:`f`g`k!(42;0;`lf);
q)(a;b;c;d)
f g k
--------
10 9 kf
20 8 je
42 69 kf
42 0 lf
but I only do this to reinforce the idea this is a basic data type in k.I can write t.f=42 and get 0011b and t.g=69 and get 0010b. I can do queries like this:
q)select from t where (f=42)&(g=69)
and that's basically the same as this: t@&:(t.f=42)&(t.g=69)
+`f`g`k!(,42;,69;,`en)
(&: is "where" and not to be confused with &)And from there it should be clear why we need this "and" behaviour. The question is what should a&b do when they're not bit vectors that would be compatible with this behaviour? 42&69 should return 42 because it's the lesser; 0b&1b returns 0b because it's the lesser... Mathematics is already quite comfortable with the relationship between logical-and and min, so this has a precedent.
Re: Stages of denial in encountering K
#366Earlier quoted context omitted.
Contrived Debian shootout benchmarks: http://www.kparc.com/z/comp.k https://web.archive.org/web/http://shootout.alioth.debian.or... Note that the relevant k program here is contained entirely on the last line of code and denoted by a comment telling you what it does: http://www.kparc.com/z/fun.k http://c2.com/cgi-bin/wiki?WardNumberInManyProgrammingLangua... Most Joy people are also k people, and Joy appears to be th…
So maybe 40x in line count if you compare an extremely verbose language like Java to K in this contrived example? That's not close to 100x and especially not close to 1000x.
k mandelbrot line count: 1
c++ mandelbrot line count: 148
Java line count: 157
Modern PL example (found on the modern shootout page, which I just found out they changed the link on):
Rust mandelbrot line count: 116
Ada mandelbrot line count: 532
And that's not even the one where k comes off the best.
Re: Stages of denial in encountering K
#367Look, I don't hate K. It's probably a pretty good language for the task it seems to have been designed for, which appears to be numerical computing. Being able to fit an entire code on a screen is an interesting concept; while I'm not completely convinced it should be a goal in and of itself it's certainly something I can't rule out as a possible productivity booster. However, I still find it problematic, and it's no…
If you're going to use a language (call it X; we're not just talking about K), then you really have to know X's syntax and primitives. There's just no other way. You also would be much better off learning X's idioms. These are standard ways of saying something. They're standard for a reason - because they work, and because everybody understands them. If you can't read them, then a lot of code is going to be difficult…
Re: Stages of denial in encountering K
#368I use to program financial applications in K/Q for a stint. Very elegant and orthogonal language. And very well documented. One major issue I had with it and other APL-ish languages: lack of skimmability. I can easily skim thousands of lines of Perl and Java in seconds and have a rough idea of what the code does. Reading K, however, requires careful and deliberate attention to every single character. I found it usefu…
That's bad in my book. I write a line once for a 100 times I read it.
Conifer forest
Vs
Pine Pine Cedar Spruce Pine Cedar ...
Re: Stages of denial in encountering K
#369Look, I don't hate K. It's probably a pretty good language for the task it seems to have been designed for, which appears to be numerical computing. Being able to fit an entire code on a screen is an interesting concept; while I'm not completely convinced it should be a goal in and of itself it's certainly something I can't rule out as a possible productivity booster. However, I still find it problematic, and it's no…
+ / ! 1000Re: Stages of denial in encountering K
#370Earlier quoted context omitted.
If you're going to use a language (call it X; we're not just talking about K), then you really have to know X's syntax and primitives. There's just no other way. You also would be much better off learning X's idioms. These are standard ways of saying something. They're standard for a reason - because they work, and because everybody understands them. If you can't read them, then a lot of code is going to be difficult…
The one specific concern I have is that some languages are readable without you knowing about the language's syntax and primitives, because it apes them from somewhere else; K is different and thus you can't apply your past knowledge to read it like you might usually be able to do.
I suspect that looking like C or ALGOL would not be all that useful for K (or Lisp, or Haskell, or Forth). The semantics are too different. A surface similarity in syntax isn't enough to bridge the gap in a meaningful way.