27 ms·
Stages of denial in encountering K
- Veedrac 7y agoK +/!100 Python sum(range(100)) Haskell sum [0..99] Rust (0..100).sum() Ruby (0..99).sum There are plenty of ultra-concise languages for toy problems like these; they are called ‘golfing languages’. Ultimately it's a bit pointless since most of the time people aren't playing code golf. (The issue with setting everything to obscure ultra-compressed keywords isn't that it's not possible to learn those keywords, but that most of the time programming is done over specific and customized domains with larger and problem-specific vocabularies.)
- bryanrasmussen 7y agoWell I guess I agree with this statement, except that I don't think K is primarily used for solving toy problems.
- Kwantuum 7y agoExcept in K all the idioms are laid flat. As pointed out in the article, the K code is the equivalent of range(100).reduce(operator.add), it encapsulates the entire meaning, there is no need for an intermediate function definition because that would be longer than the code itself.
- satokema 7y agoThe article's point is a meta-point. Congratulations on actually being part of the meme in the article.
- brazzy 7y agoThe article's point is dishonest smugassery. Congratulations on convincing people to avoid K for its community, if not the language itself.
- lolc 7y agoThat's what I'm wondering with K! What happens once I want to abstract over the basic operations?
- theamk 7y agoIf you are stuck in a boring language and want something more concise, you don’t have to give up legibility by going to K. There are plenty of languages where you are not expected to use “for” loops. Python/numpy is most accessible and probably closest to “instant gratification”. Mathematica is great for, you know, mathematics, but you’ll need a license. And there is always haskell.
- yjftsjthsd-h 7y ago> Mathematica is great for, you know, mathematics, but you’ll need a license. Do you have an opinion of Octave?
- CarVac 7y agoOctave is a Matlab clone, not a Mathematica clone.
- lopsidedBrain 7y agohttp://maxima.sourceforge.net/ http://maxima.sourceforge.net/ is closer to Mathematica, and is open source.
- kick 7y agok is perfectly readable. That's like, one of the biggest points of the post. The post mocks the mindset featured within your comment. None of the languages you listed are quite as readable as k to someone who knows it. All of the languages you listed are significantly slower and feature none of the benefits of a concise notation, even with fast.ai's Python style guide made to imitate Arthur Whitney. http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pdf http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pd...
- saagarjha 7y ago> The post mocks the mindset featured within your comment. Actually, the post pretends you know nothing about functional programming and then presents K as the solution–but, as the grandparent points out, it’s not the only one. The post actually has no comment on this. (I should also note that smugly mocking a mindset by reducing it to a caricature might help explain why people are exasperated by the post’s patronizing tone.)
- busterarm 7y agoAre reduce and lambdas really that cryptic/complex to people? I think I need an adult. -.-
- muzani 7y agoIt's not commonly taught in college. They're probably simpler than your typical for loop.
- saagarjha 7y agoI’d be quite disappointed in your degree if you were never asked to take a course that was centered around a functional language.
- DoofusOfDeath 7y agoMany smaller CS departments in the US have no such a course in their curricula. There simply aren't enough professors to maintain that breadth of courses in those departments.
- saagarjha 7y agoReally? That’s quite surprising; I would expect all of them to have some sort of “programming languages” course or similar…what classes do they have then?
- DoofusOfDeath 7y agoAFAIK most or all of those curricula do include a sirvey course for programming languages. IIUC the GP was talking about courses that specifically focused on functional programmimg.
- saagarjha 7y agoFair, but I from the context of the top comment I was talking more about being able to recognize and use basic functional constructs.
- kick 7y agoThis was written by 'RodgerTheGreat, whose comments and submissions on this site are a treasure trove.
- jes5199 7y agothe thing that's odd to me is that you could write this exact same post about other languages - a person who learns Haskell ends up writing that exact same range/reduce/plus statement. Modern lisps like Racket or Clojure take you there. Forth programmers and Joy programmers already noticed that their two languages had converged: and they'd write basically exactly this, too. Really, it's only the "mainstream" languages that are different!
- TurboHaskal 7y agoA Common Lisp programmer would write it like that too. He would then disassemble the function, run away in terror and eventually come back to rewrite the whole thing with a more efficient loop expression.
- oblio 7y agoThat's an interesting take on things. Another one would be that ~40-50 million programmers do things one way and ~10000 (totally random guess) do it another way :-)
- yesbabyyes 7y agoHis diff was lame, I'm sure the coworker would have gone along with Math.max(...list);
- tlb 7y agoThat hack isn't guaranteed to work with long lists, since the standard allows a fixed limit on argument count. For example, in Node 12: > Math.max(..._.range(0, 1000000)) Thrown: RangeError: Maximum call stack size exceeded
- duchenne 7y ago> +/!10 I personally find the given example harder to read than the equivalent in python/matlab/javascript with lodash/probably many other languages sum(range(10)) sum(1:10) With "K", you have to know a few new conventions. In the second case you just have to read, and the data flow is more obvious.
- keymone 7y agoAs I understand author’s point, your example with “sum” is only valid because “sum” word has very few meanings, especially in software engineering world. Even the word “product” would introduce certain ambiguity in context of real world codebase: is it “math” product or some “domain” product? It’s even worse with most other words. So if in any given codebase you still have to know the specific meaning of every word, how is it different from having to know specific meaning of every K symbol?
- saagarjha 7y ago> “sum” word has very few meanings, especially in software engineering world Sum types, checksums, …
- qayxc 7y ago> So if in any given codebase you still have to know the specific meaning of every word, how is it different from having to know specific meaning of every K symbol? So you never encountered namespaces then? Because that's why you use namespaces. The number of symbols is limited, which is the reason why the whole "a symbol is more explicit"-argument simply doesn't hold in general. It breaks apart pretty quickly. That's why you'll find the following sentence pretty much verbatim in most maths and cs publications: "Throughout this paper, unless otherwise specified, we use the following notations," followed by half a page of definitions. Plot twist: different authors often use different notation even within the same field of research.
- deleted 7y ago[deleted]
- sullyj3 7y agoThis looks cool, seems like it's proprietary and expensive though. Is there anything similar that's free?
- sedachv 7y agohttps://www.gnu.org/software/apl/ https://www.gnu.org/software/apl/ Most likely available through your package manager.
- kick 7y agoBetter: Free software K interpreter: https://bitbucket.org/ngn/k/ https://bitbucket.org/ngn/k/ Arthur's K interpreter isn't actually that expensive for casual use anymore (it's free for most non-commercial use and you can download it off the Shakti website pretty easily), though. Not that I'd recommend it: Arthur's a genius, but nothing's worth using proprietary software for. What I usually recommend for learning the paradigm is J, largely because it has far better resources than anything else in the space. J's labs are wonderful, and the books Ken Iverson wrote before he died (all available for free) are great both for learning the language and also for learning many other things. GNU APL is nice, and by no means am I trying to diss it: it's just not the best for learning, in my opinion. Its info pages are really nice though, like most GNU info pages.
- sedachv 7y agoThere are a lot of books, tutorials, and papers on APL and APL2, which are applicable to GNU APL.
- kick 7y agoI don't believe so? I started out using APL2; GNU APL seems distinct in ways that are noticeable. Certainly not in a bad way, but I think enough to cause confusion for any newcomer reading said books, tutorials and papers.
- 7y ago
- kazinator 7y ago> When the entire system fits in a page of code you can understand everything about it from the top down. I'm sorry, but that sounds like the juvenile fantasy of someone who is still in their programming puberty. Good luck fitting an operating system, web browser or air traffic control system into a page of code.
- gallabytes 7y agothere almost certainly is an encoding such that every program any human will ever write fits in 128 bytes, though I doubt we'll ever design one. to convince yourself of this, notice that you don't expect to ever produce two programs with the same blake2 hash. there's a lot of room for improvement in conciseness of code. I would still be surprised if it was meaningfully possible to write a full-featured modern OS with one page of APL
- deleted 7y ago[deleted]
- kazinator 7y agoHashes do not encode; to convince yourself of this, try to recover a program from it blake2 hash.
- Dylan16807 7y agoI think you'd have to write the "Do what I mean." interpreter before you have any chance of making programs that compact.
- PeCaN 7y agoMaybe I should've said a "screen" instead of a "page" (if you have two files open side-by-side and they both fit on your screen it's the same benefit). And I admit it is slightly hyperbolic (to make a point about the virtues of being able to see a significant portion of your project at once). Large projects will be more than one screen of code, although perhaps surprisingly few. (This actually influences how I organize code, in that the "screen" becomes a logical unit, and I try to keep the API surface of each screen really small.) I'm working on a programming language project to try to get even denser. >Good luck fitting an operating system, web browser or air traffic control system into a page of code. Aaron Hsu's co-dfns compiler (optimizing compiler for a subset of APL to the GPU) is 3 screens https://github.com/Co-dfns/Co-dfns/tree/master/cmp https://github.com/Co-dfns/Co-dfns/tree/master/cmp (I can fit the entire codebase on my three monitors). This K text editor is way less than one screen https://kparc.com/edit.k https://kparc.com/edit.k (Funny you should mention OS. I'm eager to see how many pages kOS is. AW notoriously hates scrolling.) Web browsers are a lost cause, I'll give you that one.
- beiller 7y agoThe javascript example of list.reduce((x,y)=>Math.max(x,y)) should have been just Math.max(...list)
- saagarjha 7y agoSuggested already, with a rebuttal: https://news.ycombinator.com/item?id=22523151 https://news.ycombinator.com/item?id=22523151
- codegladiator 7y ago> list.max(Math.ordering)
- caymanjim 7y agoNot mentioned in the article is that the K programming language is used for kdb+, which is a fast in-memory time-series database that's heavily used in the finance industry for securities trading systems. I've worked with it a tiny bit, but the pros are all Dark Wizards.
- rubyn00bie 7y agoOnly because earlier today I so definitely thought about the whole "code is a liability (debt)" reality we all live in... that is to say, I'm spit-balling here: but for once K makes me go "oh shit!" and not because of the craziness of its syntax... rather, if that syntax is so precise/terse, and even if to the outsider it looks fucking insane, does it have a wicked lower TCO because you literally have insanely less lines of liability in your code, libraries, dependencies, etc? Is that the reason finance uses it, they maybe empirically know what the rest of us don't seem to grasp? Or just because it's so domain specific? Or... something else entirely?
- hmry 7y agoThe "amount" of code is the same as in any functional language though. It's just written in a smaller text file.
- chrispsn 7y agoArthur tries to choose primitives carefully so that the amount of steps is smaller than other languages (see the 'product' quote in another comment). So even if you give each symbol an English name, the code will often end up smaller.
- wpietri 7y agoIn which case it seems like two things are being conflated a lot here: terseness and better primitives. I'm opposed to the first, but very interested in the second. Is there a language you think focuses on approachability and readability but keeps the good parts of K?
- chrispsn 7y agok9 (from Shakti) will have optional word equivalents for some symbols (or at least common compositions) by default. Have you looked at q? numpy has a lot of k/APLish primitives built in. fml was also interesting but never made it past the spec stage: https://www.reddit.com/r/apljk/comments/etpbbf/fml_an_optimizing_functionoriented_array/ https://www.reddit.com/r/apljk/comments/etpbbf/fml_an_optimi...
- chrispsn 7y agoFrom Arthur: design goal: speed write fast, run fast, modify fast. minimize product of vocabulary and program size. https://a.kx.com/a/k/readme.txt https://a.kx.com/a/k/readme.txt comprehensive programming environments (programming, files, comms, procs, ...) are depressingly complex. commonlisp, c/lib/syscalls, java, winapi are all in the 1000's of entry points. many with multiple complex parameters. with k we try to do more with less in order to write correct programs faster. https://web.archive.org/web/20041024065350/http://www.kx.com/listbox/k/msg04791.html https://web.archive.org/web/20041024065350/http://www.kx.com... > Just curious, but does the state of California charge you a large tax > for each character in a variable name? yes. we also try to fit our algorithms onto licence plates. https://web.archive.org/web/20040823040634/http://www.kx.com/listbox/k/msg02291.html https://web.archive.org/web/20040823040634/http://www.kx.com... For some 'licence plate' K algorithm dissections, you might like this Twitter account: https://twitter.com/kcodetweets https://twitter.com/kcodetweets
- kstenerud 7y agoThe readme examples remind me of Perl code. Example: print<>!~($/=$")+2*map 1..$s{$_%$'}++,<>
- deleted 7y ago[deleted]
- gerikson 7y agoThis one comment managed to insult both K and Perl coders...
- Ma8ee 7y agoI don't think Perl coders need any help with that.
- wruza 7y agoFor non-perl guys: It is a cryptic example, because it uses ‘system’ variables in a non-obvious way, not because of syntax. I can read it syntactically just fine, but have to look up for names to understand what it does. A fully uncodegolfed variant would require the same effort here.
- sklivvz1971 7y agoThe irony of claiming to represent a readable language, that others are in denial of reality about this, and presenting your thesis on a '90s looking website with typographic lines spanning almost 400 chars at 100% width... ABTASTTSBMR than the whole sentence. OK.
- neonate 7y agoThat objection seems trivial.
- sklivvz1971 7y agoThe whole article is trivial and trite, yet dressed up as something novel.
- neonate 7y agoI don't think so. Even if that's true though, you could do better.
- saagarjha 7y agoI very much liked the design. Perhaps I'd slap a max-width on it, but other that that it was a delight to read. (And my browser's reader mode really liked it, too.)
- LandR 7y agoDisplays fine for me on my desktop. I'm happy with just text.
- hasa 7y agoSome people find entertaining from these extremely compact syntax languages. I have hard time to understand them, but such is life.
- floatingatoll 7y agoRegular expressions are a more concise way of writing string matching and extraction code, often exponentially more efficiently than without. They’re also usually more compact than spoken English can represent. For example, this proofreading regex detects possible issues in spelling: /(?<!c)i(?=e)/
- tkfu 7y agoThat's a really bad proofreading regex, though, because it will be wrong more than a third of the time--which is much, much higher than the expected real spelling error rate. The "i before e except after c" rule only has a high success rate when you add the caveat that it only applies to words where the ie or ei makes the sound [i:] (like in "believe", for example), and that caveat isn't expressible via regex.
- quelltext 7y agoDoesn't that regex detect correct spellings instead of wrong ones? I.e. it matches tier, tie, etc.
- floatingatoll 7y agoYes. Good eye :) The other comment is also quite accurate: it doesn’t properly grasp phonetics.
- quelltext 7y agoFWIW, I agree with your argument (I guess). Regular expressions are complex and oftentimes a tool might be necessary to get a better idea of what an expression will match. However, if we were to make the language to describe them more verbose that'd still not solve this issue. Having a concise way to describe them is a good thing. Those who grok them can do so quickly without having to read several lines of a more descriptive language and those who need assistance can still plug them into a tool.
- tus88 7y agoIs this C in Russia?
- smadge 7y agoUsing / for reduction reminds me of the Bird–Meertens formalism.
- msla 7y agoMy problem with K isn't its syntax, it's its culture: People who are so self-satisfied with their ability to read their own code they refuse to give variables meaningful names, aping mathematical tropes they half-understand at best, because those mathematical equations are only tolerable in the context of a paper where the rest of the lifting is done by natural language prose. They eschew comments without realizing that those comments enable terse expressions by showing you have the basic maturity to express yourself in a way others can understand. Knuth tried to move us to that state with Literate Programming. How many K programmers use Literate Programming? One? Two? Any?
- kaminari 7y agoElsewhere in this comment section, someone mentioned a HFT firm that extensively used noweb and K.
- rgrs 7y agoauthor ended article with > Leaning back in your chair, you think to yourself: > |/ what does this translate into?
- floatingatoll 7y agoI reversed each of my list of objections.
- icen 7y agodyadic | is or, or max. So e.g. 4 = |/1 2 3 4
- yiyus 7y agoRoughly: let max = list[0]; for (let i = 0; i < list.length; i++) { max = Math.max(list[i], max); } With a|b, you get the maximum between a and b. / is reduction. So, |/list, will be equivalent to list[0]|list[1]|list[2]|...|list[n], i.e. the maximum value in the list.
- muzani 7y agoI have fallen in love with this language. How I do replace Java(Script) with this?
- brazzy 7y agoDisingenious and unconvincing, like a sales pitch for a product that is actually bad for you. Yes, that kind of syntax can be wonderfully terse when doing simple arithmetic operations on lists of integers. Most programming work does not consist of doing simple arithmetic operations on lists of integers. If you want to convince me that this languagy useable for anything but toy problems specially chosen to demonstrate the language's strengths, show me how it can be used to handle an HTTP request with some special cases for certain headers, or to parse a custom date format with variants, or to implement a game with realtime user input.
- chrispsn 7y agoHow about an OS? https://gist.github.com/chrispsn/da00835bb122c42f429a084df83fd746 https://gist.github.com/chrispsn/da00835bb122c42f429a084df83...
- Drakar1903 7y agoThis is what - I presume - is their implementation of sending an e-mail E:[u:();e:{a::?[a;x;y];J(x)+#y};cz:{$[#u;e/_`u;]};kx:{u,:,(j,j+#x;k_a);e[k]x};kb:{$[=/k;J j-1 0;];kx""};cx:{kx cc`};cv:{kx@9'`}] A:[w::_W%F;j::k;k:0 0;J:{k::2#0|x&#a};lx:{J j+x};y::V+F0,j;z::1'(V;w[1]$a)],E U:{(`Z,'!Z).'+x};V:0;i:0;I::`Z,(!Z)(#Z)!i;y:{I .`y};zf:{$[`kt=x;i+:1;^`W`F?x;I . x;. x]};u::F[0]!#Z;W:{U`V,,u,'0;U`W,,(-':1_u,x),'x 1};z:{U`z;1'(V;U[`a]{$[#x;"";y]}'$!Z;3)} Z:`to`cc`subj`!A$/:4#() This looks like an exercise in obtuseness.
- bartread 7y agoI tend to agree: falls into the category of "just because you can, doesn't mean you should." Actually, that's perhaps a bit harsh. I have some pretty obscure hobbies, and there's certainly nothing wrong with doing this sort of thing if you want to. Still, having done so it's a bit rich to then look askance at the rest of us like we're all idiots for not choosing to go down a similar route with our own systems.
- 7y ago
- dang 7y agoA million-line program isn't readable by anybody, no matter how readable the language is. If the equivalent program can be written in, say, a thousand lines in some more concise language, that's more than worth the learning curve, even if the language is strange and off-putting.
- buzzkillington 7y agoThat depends. When my assumptions about the underlying problem are wrong a million line program is much easier to fix than a thousand line one. Or rather, a thousand line concise program in a quirky language will become a million line program in a quirky language when exposed to changing business requirements.
- adrianN 7y agoIf the language allows you to simplify the program sufficiently it might be easier to just rewrite it from scratch when the requirements change. I doubt that this is the case for any language, but you know, in principle it could happen.
- buzzkillington 7y agohttps://en.wikipedia.org/wiki/Write-only_language https://en.wikipedia.org/wiki/Write-only_language >Languages that are often derided as write-only include APL, Dynamic debugging technique (DDT), Perl,[2] Forth, Text Editor and Corrector (TECO),[3] Mathematica, IGOR Pro and regular expression syntax used in various languages.
- 7777fps 7y agoYou've got me wondering about the utility of a genuinely write-only language. As a thought experiment, would there be benefit to letting functions only be written once? No-one could come along and break code by changing a function. If you wanted to fix a bug in a function you would have to write a new copy and explicitly update callers to use the new version. A lot of maintenance overhead? Possibly, but tooling would take care of the majority of it. It would be useful to be explicitly know not just when a function has changed but when the functions it calls have changed. You would need a naming convention, instead of Main you would need something like Main#23145. It would tick over very regularly. Library functions like CalculateTax#12 would tick over less frequently. By calling the old revision you could call the old code if you didn't want to update a module or function. Perhaps you could extend that name to be something like Namespace.Name#IndirectRevision.DirectRevision.Hash which would allow tools to more quickly extract when the change was made in the logic of the function itself or when the change was in dependents. This would be an alternative strategy to maintenance to IoC. Instead of treating dependents like they don't affect the code being executed, we can control instead the version of code By forcing code change in all callers, you build up an explicit picture of where bugs happen but more important see also at the impact of those bugs on other places. It would need great tooling to get over the paradigm shift of moving away from IoC but I think it would be interesting.
- Athas 7y agoPeople are so quick to reject K and APL-style languages for superficial reasons that they never get to the deep and interesting reasons! I am mostly familiar with APL, but I think the things I appreciate and dislike are about the same in K. One interesting philosophical difference, at least among some APL programmers, is that building abstractions should be avoided. TFA has a hint of that philosophy, in its suggestion that perhaps naming (the root of abstraction) hinders clarity. I think this is definitely worth considering, and it doesn't really have anything to do with the (supposedly) cryptic syntax. One reason I don't like K/APL-ish vector programming is performance. I once spent some time working with others on a GPU-targeting APL compiler, and I found that some common programming patterns are quite antithetical to good performance. In particular, the use of "nested arrays" (not the same as multidimensional arrays) induces pointer structures that are difficult to do anything with. Such nested arrays are typically necessary when you want to do the equivalent of a "map" operation that does not apply to each of the scalars at the bottom, but perhaps merely the rows of a matrix. Thus, control flow and data are conflated. This is fine conceptually, but makes it difficult to generate high-performance code. Another concern is that encoding control flow as data requires a lot of memory traffic (unless you have a Sufficiently Smart Compiler; much smarter than I have ever seen). Consider computing the Mandelbrot set, which is essentially a 'while' for each of a bunch of points. An idiomatic APL implementation will often put the while loop on the outside of the loop over the point array, which means it will be written to memory for every iteration. In other languages, it would be more idiomatic to apply the 'while' loop to each point individually, which will then be able to run entirely in registers. You can also do that in APL, but it is normally not idiomatic (and sometimes awkward) to apply complex scalar functions to array elements. Just look at this Mandelbrot implementation from Dyalog; they do it in exactly the way I described: https://www.dyalog.com/blog/2014/08/isolated-mandelbrot-set-explorer/ https://www.dyalog.com/blog/2014/08/isolated-mandelbrot-set-... Specifically, the conceptual 'while' loop has been turned into an outer 'for' loop (this is OK because the 'while' loop is always bounded anyway): :For cnt :In 1↓⍳256 ⍝ loop up to 255 times (the size of our color palette) escaped←4<coord×+coord ⍝ mark those that have escaped the Mandelbrot set r[escaped/inds]←cnt ⍝ set their index in the color palette (inds coord)←(~escaped)∘/¨inds coord ⍝ keep those that have not yet escaped :If 0∊⍴inds ⋄ :Leave ⋄ :EndIf ⍝ anything left to do? coord←set[inds]+×⍨coord ⍝ the core Mandelbrot computation... z←(z*2)+c :EndFor
- saagarjha 7y agoLook, 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 not really about the language itself: it's more about how it's promoted in the article, by the people in this thread, and in general. Specifically, the claims it's perfectly readable, and anyone who says anything otherwise is either stupid, lying, or too poor to understand it are not useful. (Yes, you know who you are for that last one. You're not helping your case.) The fact of the matter is that most programmers are used to ALGOL-esque syntax, and there is significant value in being able to lift concepts and interoperate between those languages at a superficial level. Every "inspired" languages hits these issues, depending on how "strange" it is: Objective-C is ugly, Lisp is alien, and on the far end APL derivatives are simply labelled as unreadable. That doesn't mean they're bad languages, but to those promoting it: drop the attitude, and understand why we have reservations. Your language isn't the "true" way to program, that only the chosen elect can understand and lecture us on. Don't ignore or gloss over languages that have similar features to yours. We want to hear what the interesting things are that you can do in the language, actual guidance for how we can adapt to the language (not: "one-letter identifiers are just what we do; deal with it"). Thanks.
- yiyus 7y agoI 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 you expect to figure it out based on your knowledge of English, it will be terribly frustrating. This does not mean that German or Dutch (which share roots with English) are better languages, or even easier to learn. Do not expect your Chinese teacher to give you a different answer from "these weird symbols are just what we do; deal with it". This article is quite good. Clearly the author understand your reservations and he is saying: give it a try and it will click. The learning material might be better, but it's there (start with Iverson and work from that). It's much easier than learning Chinese!
- uryga 7y agowhat is `<<` ("ordinal") supposed to be doing? i understand how `<` works, but how is it useful to apply it a second time? the closest i got to finding some pattern is this: >>> xs '34210' >>> grade(xs) [4, 3, 2, 0, 1] >>> grade(grade(xs)) [3, 4, 2, 1, 0] # :O where grade = lambda xs: ( [i for (i,_) in sorted(enumerate(xs), key=swap)] ) swap = lambda p: (p[1], p[0]) no clue what it means though. (i guess "ordinal" really is too ambiguous...) EDIT alright, i see it now - `<<xs` is "for each item x of xs, where does x land when you sort xs?
- icen 7y ago< grades upwards: for each element, the element of the returned array is its position if the array is sorted. x: 10?A:"abcdefghijklmnopqrstuvwxyz" x "ysyselacwl" +`x`y`z!(x;<x;<<x) x y z --- - - "y" 6 8 "s" 7 5 "y" 4 9 "s" 5 6 "e" 9 2 "l" 1 3 "a" 3 0 "c" 8 1 "w" 0 7 "l" 2 4 So <x gives a sort index, <<x tells you how far each element is from the minimum in that sort index
- uryga 7y agoyeah, i figured it out eventually. since you seem knowledgeable about K, would you mind taking a look at my second comment in this thread (about inverting permutations) and seeing if it makes sense? thanks!
- i_don_t_know 7y agoI still don’t understand what the numbers in column y mean. I understand column z and that’s also what grade up is returning in John Earnest’s oK: x:“baced“ <x 1 0 2 4 3 <<x 1 0 2 4 3 That is, for example, when sorting, the item at position 1 in the original string (“a”) moves to position 0 (the beginning of the sorted string). So in the end you get “abcde”. What does column y mean? If I sort the original with it, I get “wllaysysce”. Has this changed between versions of K?
- i_don_t_know 7y agoNevermind. I've figured it out with the help of the reference manual at http://www.nsl.com/k/k2/k295/kreflite.pdf http://www.nsl.com/k/k2/k295/kreflite.pdf. I knew it was a permutation but I applied it incorrectly.
- mthwsjc_ 7y agowhat is this orange website the post mentions?
- vermilingua 7y agoLet me think.........
- LandR 7y agoHe might not be joking, I've always browsed HN with dark mode enabled. For me it's a light and dark grey website :)
- muzani 7y agoIt took me several hours to get it. I'm not sure if this was meant to be sarcasm, but thanks.
- bori5 7y ago“ and you can add 5 to an entire matrix at once as easily as a single number. Why you would want this property remains elusive-...”. Why would that be elusive I wonder ? MATLAB has been doing it since the 80s as an example and that exact elusive feature would have been used countless times.
- andybak 7y agoThose words were spoken "in character". The idea was that some readers would chuckle at the naivety.
- bori5 7y agoAnd many time’s I shake my head at how people miss humor/sarcasm on HN. Got me.
- AstralStorm 7y agoAlso Fortran and C++ Eigen matrix math library. Very useful for anything that is non-trivial math.
- heinrichhartman 7y agoLooks like the author figured it all out at the very beginning: > If each punctuation character in the K is a separate part of speech, and you reverse their order + / ! 100 plus reduce range 100 This seems to be how this works. Compare that to math equations like these ones: https://en.wikipedia.org/wiki/Maxwell%27s_equations#Formulation_in_SI_units_convention https://en.wikipedia.org/wiki/Maxwell%27s_equations#Formulat... You would not expect them to read them like a paragraph. You are expect to read them symbol by symbol and unpack from the inner out. K seems to be a dense language. Expect to read it symbol by symbol, not word by word or line by line. If will be come more readable if you (1) slow down (2) get used to the programming patterns. Not saying K is a good language or anything. But the frustration of the author seems to have more to do with impaticence and mismatched expectations than with flaws in the language itself.
- yiyus 7y agoThe author is a K professional developer who works with K on a daily basis and have implemented a K interpreter in JS (oK). He is not frustrated, he is making a point. It looks like you perfectly got the point.
- heinrichhartman 7y agoThanks for the clarification.
- buzzkillington 7y ago>You would not expect them to read them like a paragraph. You are expect to read them symbol by symbol and unpack from the inner out. As someone who has a bunch of letters before my name because of physics, no. You don't read physics symbol by symbol. You expand those symbols to pages and pages, meditate on those pages and achieve enlightenment on one small aspect of the problem. There is so much implicit state in those equations they are basically meaningless. A nice book that deals with all the implicit state and terrible unclear notation used in physics: https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Classical_Mechanics https://en.wikipedia.org/wiki/Structure_and_Interpretation_o...
- mhd 7y agoThe problem is also that you encounter K/APL in these circumstance, hardcore math functions or ad hoc queries. I'd say that most languages look their worst in these circumstances, deeply nested for loops for e.g. 3D math in C aren't exactly instantly clear either. Once you see e.g. input verification or other more "tedious" parts of programs, things get decidedly less cryptic. And less optimized/concise, of course. A bit like the people who complain about GUI hello world programs taking 10 lines.
- Beltiras 7y agoI went through a similar transformation when I finally understood LiSP. I knew Python and had programmed in it for several years but it was breaking into Scheme that changed my approach. I wonder if learning new paradigms always changes how you use other languages.
- gerikson 7y agoAccording to Peter Norvig, you were half-way to Lisp using Python: https://norvig.com/python-lisp.html https://norvig.com/python-lisp.html
- kazinator 7y agoAccording to Guy Steele, if you're a C++ programmer using Java, you've been dragged halfway to Lisp. https://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg04045.html https://people.csail.mit.edu/gregs/ll1-discuss-archive-html/... So by that estimate, if you switch to Python you're another halfway to Lisp (three quarters of the way from C++).
- wglb 7y agoI could never figure out how Java is in any sense halfway to Lisp. Python, maybe.
- lispm 7y agoThe reference point is C++. What makes Java nearer to Lisp than C++? Mostly the Java runtime, the JVM. C++ basically comes with some kind of manual memory management and raw data layout. Lisp comes with Garbage Collection and managed memory. In Lisp one passes references to arrays and other objects around. The runtime tracks which objects are of what dynamic type and of what size. The garbage collection may be a simple mark&sweep or a more complex, say, generational GC. The first garbage collection was developed for Lisp around 1960 and has then slowly spread to other languages. C++ was object-oriented, but with a more traditional non-GC approach. Java changed that.
- goto11 7y agoIf you want to sell me a language do: - Explain what particular use cases the language is optimized for - Show its advantages compared to the alternatives - Tell me honestly what tasks it is not suited for do not: - Use blantant strawmen to make the alternatives look worse. - Tell me I am an idiot
- SamReidHughes 7y agoUltimately, you’re the one responsible for your opinions about the language, not the author.
- randallsquared 7y agoIt seems like you're inferring a lot which wasn't said, which is quite consistent of you! :)
- wpietri 7y agoI think the simple explanation here, per POSIWID, is that people who do the latter things do not in fact want to sell you on a language. It reminds me of the people who liked a band until it got popular. The point isn't the thing itself, it's having a reason to feel superior to other people.
- sriram_malhar 7y agoI love the brevity of regular expressions and use them on a daily basis. It is the same argument that keeps me returning to K: the syntax is terse and compact, the semantics are simple and composable, and your eyes get used to it. Beyond a point however, I cannot read my own regex's after a month's absence. Which is why I use perl's /x modifier extensively to split up regex components onto multiple lines and to document them thoroughly, even if they are for throwaway scripts, because I don't always throw them away!. For example: $_ =~ m/^ # anchor at beginning of line The\ quick\ (\w+)\ fox # fox adjective \ (\w+)\ over # fox action verb \ the\ (\w+) dog # dog adjective (?: # whitespace-trimmed comment: \s* \# \s* # whitespace and comment token (.*?) # captured comment text; non-greedy! \s* # any trailing whitespace )? # this is all optional $ # end of line anchor /x; # allow whitespace (source: https://www.perl.com/pub/2004/01/16/regexps.html/ https://www.perl.com/pub/2004/01/16/regexps.html/) This is where K fails me. It may not be a fault of the language, but everyone in the community has bought into this strange idiomatic style. I can't imagine debugging it, or checking it for correctness, or foisting it on a less experienced developer. Here's a canonical example an xml parser, on their website. https://a.kx.com/a/k/examples/xml.k https://a.kx.com/a/k/examples/xml.k Where's the pedagogy? Where are the comments? Why is this line noise considered acceptable?
- geocar 7y ago> https://a.kx.com/a/k/examples/xml.k https://a.kx.com/a/k/examples/xml.k > Where's the pedagogy? Where are the comments? Most of that document _is_ comments. There's a comment on almost every line, very similar to your perl example. Comments begin with a "/" character which doesn't have a function to the left (e.g. whitespace). First we have some constants (L,W,B,S,R) which refer to the left-bracket, whitespace (which includes blank), blank space, and slash and right-bracket. We've also got some utility functions (cut;join). These are simple enough they don't require any special explanation to the K programmer who reads this. Then we have a function that produces an xml-entity from a character. The author assumes octal is required, so (needlessly) converts to that. The octal string (with a leading zero) is concatenated onto ";&#" then rotated so the ";" appears at the end (1! is cute). I would probably write this differently, because: 1!";&#",$_ic is shorter. We then have a function that does the reverse, cutting off the first three characters after rotating (which is the ";&#" string again) and converts the octal digits back into decimal. This is probably wrong because real XML documents will probably prefer decimal entities, but perhaps the author wasn't dealing with these. I would certainly write this differently if I changed oc (as above). Now we have the helper function xc and cx (whose names suggest they are converting from character-to-xml and xml-to-character respectively). This is a stylistic observation, we can also see this from the comment, or by reading the code (if we know what XML is). These implementations are pretty basic, just using ssr to do repeated search/replace on the entities (note that ssr knows that ? character means any). You get used to it. > Why is this line noise considered acceptable? One major challenge reading inscrutable perl scripts is knowing where the execution begins. Perl just has so many rules for parsing it you really need either wizardry or patience to know how to pull it apart, but K is extremely regular: there's only one way to parse it, and shortly after learning it you also learn (quickly) you can insert trace statements that don't change the meaning of the rest of the statement to learn a new operator (or a new use of an operator you didn't know). I note this especially as it is extremely hard to do in perl (and even other Iverson languages including APL and J). Line noise is a subjective quality that goes away (at least in this case) when you become more fluent in K. I don't believe this is necessarily true of all compact languages though.
- noobermin 7y agoSeeing this article and the top comment, is this that contentious an issue? I wasn't aware people care that much about Algol vs. APL-ish languages.
- Tomte 7y agoI totally buy that this is elegant for small number- or lust-based things, but since a financial database is named as the flagship product: how does I/O look like in K? Both user input and disk access. How do you make a user interface? How do you networking? Is it still as elegant?
- aw1621107 7y agoI've seen a few posts here and there over the years about array languages, but I can't recall any (or any discussion in their comments) that have mentioned any disadvantages beyond more human factors. So for the k/q/APL/array language gurus out there: in what situations would I not want to use k or another array language, if the relative obscurity of the syntax and mental model were not a factor (e.g., assuming you, your team (if any), and anyone who would ever look at your code would be very familiar with the language and idioms)? I may not want to choose Go or Java because of latency concerns, or Rust because of compilation speed/iteration time concerns, or C/C++ because of safety issues, or Python/Ruby/Javascript because of performance issues. Why would I not want to pick k?
- 7thaccount 7y agoPerformance 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. K is very expensive. Dyalog APL is pretty reasonable, but still costs money to use and royalties in certain situations. I think any decent developer can pickup array languages, but many won't want to as they'd rather have something more mainstream (Java, JS, C++, Python...etc) on their resume. So it might be difficult to hire.
- spopejoy 7y ago> 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 so hard to hire for, not to mention its limited applications for teams (kdb is NOT a good multi-user database). However elegant it may be, it's doomed to be a COBOL if this is where its main userbase stays. J is open source, but I can't get a handle on how battle-tested it is. It always seemed like Kdb was the real product that got used in anger. Personally I think array-heads should spend more time with Haskell, since it has the ability to be massively terse and point-free, has type inference, loves infix gobbledygook, can be tuned for great performance, and is thoroughly open-source.
- i_don_t_know 7y agoHow does error handling work in K? For example, what happens when you try to read a file that doesn’t exist? How does the read function indicate failure to the caller? How does the caller check and recover (show an error to the user and continue with some default values)?
- RodgerTheGreat 7y agoIf primitives fail, they raise a signal. There is also a primitive for unconditionally raising a signal. Most flavors of K have a primitive called "error trap" which captures signals emitted by a function application, should they occur: f:{11 22 33 x} .[f;,1;:] 0 22 .[f;,4;:] (1;"index") If a signal is not trapped, K pauses execution and opens the debugger, where a user may interactively inspect the environment, evaluate code, and resume: f 4 index error {11 22 33 x} ^ > x 4 > Overall not that different from try...catch in a garden-variety interpreted language with a REPL.
- i_don_t_know 7y agoThanks! That's fairly straightforward and, I guess, avoids having to pass a closure.
- snicker7 7y agoI 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 useful to maintain documentation on how to /read/ the code (almost a literate programming approach).
- BiteCode_dev 7y agoThat's bad in my book. I write a line once for a 100 times I read it.
- Roboprog 7y agoOTOH, there is something to be said for reading fewer lines in some cases. Conifer forest Vs Pine Pine Cedar Spruce Pine Cedar ...
- threatofrain 7y agoIsn't Lisp that Conifer forest.
- oddthink 7y agoYeah, I agree. I wrote some mortgage prepayment models in q for a while, but didn't dip into K itself. Q is fantastic as a database query language (assuming you have time-series databases and are mostly doing fairly simple operations.) Implementing a full model in it is fine, but can get hard to maintain. Also it has (or had, maybe they fixed it) a bunch of weird quirks, like "sum foo" skipping all the NAs in a list while "+/foo" didn't, resulting in NaN. (Or maybe it was +/ over an int array didn't work while a double array did. I forget.) Arrays of dicts were immediately turned into tables, which didn't work the same as an array of dicts, etc. But, yeah, it's not crazy implementing things in q/K, as long as they're mostly linear things. Trees are hard, iterative methods are hard, and it's really hard to skim code, other than to just rely on names and comments.
- ricardobeat 7y agoThe name (and editor extensions) are taken by another 'K framework': http://www.kframework.org/index.php/Main_Page http://www.kframework.org/index.php/Main_Page
- kick 7y agok spawned in 1992. When did this framework come about?
- carapace 7y agoThis article should end with something like, "...and then you find out about arcfide's Co-dfns compiler..." https://github.com/Co-dfns/Co-dfns https://github.com/Co-dfns/Co-dfns You don't have to like it, but the existence of K, et. al. shows that most of us are wasting a huge amount of time and energy using bad tools. These things are so powerful and not that hard to learn.
- Nursie 7y agoIt shows no such thing. It shows that you have found something you think you can be productive in and that you like, not that the rest of us are on the wrong track.
- carapace 7y agoI can't agree. (BTW, I don't like K, and I don't use it, but if I did I'd like to think I'd be productive in it.) This little system runs circles around entire sub-industries of other software. The fact that it exists and uses one or two orders of magnitude less time and code than other systems is significant. It's like axes vs. chainsaws. If the job is to log a forest the latter will be better than the former.
- Nursie 7y agoLess code is entirely irrelevant unless for some reason you're concerned about a few k of storage for your source, less time appears to be speculation. If people can make working, maintainable software other ways, particularly if those other ways have large, established ecosystems of dependencies, then they are likely doing it right regardless of how much you like apl.
- carapace 7y agoAgain, I don't like APL. Less code -> fewer bugs, all other things equal, eh? > large, established ecosystems of dependencies ...are actually a symptom of failure to refactor. Ideally, over time, you code base approaches the Kolmogorov complexity of the problems it solves. > If people can make working, maintainable software other ways ... ...but it takes 10x-100x more code, RAM, CPU power, developer time, etc. than if you hadda used K, then you're leaving money on the table.
- traitsnspecs 7y agoHow do people do error handling in K? Or is the data typically well-formed in real programs? Not bashing anything, I'm just genuinely curious.
- at_a_remove 7y agoMy hat is off to the people who can handle this kind of thing; I myself cannot.
- clarry 7y agoDo you really think you could not, even after taking a few weeks to study and practice?
- at_a_remove 7y agoProbably not, no. I could easily see myself becoming dejected after printing out a few cheat sheets and buying some relevant books. I would have attempted some exercises and done whatever toy projects with an increasing feeling of dread that I was simply aping what was before me only to find what I thought I had learned had slipped away in a weekend. Should I get much further than that, I would then try to solve an actual problem I had with it and that would be the end of it as I would stagger into realms of development environments and dependencies to try to get the right libraries in order, I would look for advice online and tentatively ask questions only to be blasted for using the wrong dialect of whatever, or have my questions misconstrued until I could be informed that what I really have is an XY problem, I don't really want what I asked for after all. What a relief to me. At that point I throw in my hat and go back to what I am used to. I know myself well enough to know that I just haven't the grit or patience to torment myself with trying to find an application for the befunge du jour and, as such, learning it becomes a Glass Bead Game for me. If my life depended on it, perhaps, but this reminds me too much of the "executable line noise" I escaped: Perl, with a kind of sly terseness I associate with any number of obfuscations as a kind of puzzlebox monument to the "cleverness" of packing something into a single line I have had to slam into while programming. I lack the vim to tilt at these windmills.
- tangentstorm 7y agoThat's a pretty good set of things to visualize if you want to feel defeated before you even get started. I write K for a living, and J for fun. J is WAY crazier, and I learned it specifically because it was so weird and crazy. I kinda wanted to remember what it was like to be a beginner again. In all these languages, you can always fall back to doing things the "old way"... They all pretty much support structured and functional programming with loops and functions and whatnot. It's just there are lots and lots of shortcuts, and you get used to them over time. (Also for what it's worth, the communities around vector languages do tend to be pretty friendly and welcoming...)
- starpilot 7y agoK is a gift from God. That is all.
- LessDmesg 7y agoI 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 is a pretty limited playground.
- earenndil 7y agoArthur wrote an OS in k with some c. Not public, but geocar can probably talk more about it if he shows up.
- kick 7y agoForth: OpenFirmware (previously seen in Power Macs, pretty much every Sun device until Sun died, so on. Canon Cat (greatest text editor of all time, by Jef Raskin, the guy who made the Macintosh) Forth Has Been to Space (multiple times, but who's keeping score?): https://www.forth.com/resources/space-applications/ https://www.forth.com/resources/space-applications/ OKAD, which was used to create the processor with the lowest power usage per instruction in the entire world. k: Important, no, but a substantial volume of stuff. Text editors, GUIs, window managers, operating system completely independent of any other, a pretty important and very expensive database, so on. k, unlike Forth, came after software was seen as IP. Software as IP has made a lot of people very angry and been widely regarded as a bad move. k's ancestor, APL, was used in quite a few things quite elegantly, and while k is different, it's not different enough to be a different paradigm. Some examples: first practical electronic mail system, first widely-used electronic mail system (used for Carter's successful Presidential campaign, for example), first worldwide computer network, I could go on. That k hasn't seen as much groundbreaking work done in it is less because of the language itself and more because of the insane costs, trigger-happy lawyers of kx, and money. Of course, when you asked this of Forth the other day, you were trolling ( https://news.ycombinator.com/item?id=22319154 https://news.ycombinator.com/item?id=22319154 ), so I imagine I might be wasting my time.
- LessDmesg 7y ago
- FeepingCreature 7y agoDlang: list.reduce!max
- goto11 7y agoSome context often missing form these "code golf" showcases: Domain specific languages have syntax optimized towards specific tasks. This often means very compact symbolic expressions which looks completely inscrutable to outsiders but are highly efficient when you know the language. String processing in Perl, pointer arithmetic in C, selectors in jQuery. Nobody can guess what the code does by looking at it, you have to learn the language. But it is worth the investment when the task in question is often used. So the question is, are you working in a domain where the investment in learning a particular DSL will pay off? But this context is completely absent in the article. By comparing the K syntax for "reduce" with a for-loop, it assumed the competition is systems languages like C or Go where a for-loop is idiomatic. But then the question is, how often do you use "reduce"-like operations in this domain anyway? It is really worth optimizing the langauge towards? If on the other hand the article admitted K is a domain specific language optimized for numerical processing, then a reasonable comparison would be against Numpy or Matlab, perhaps Haskell, not for-loops.
- tangentstorm 7y agoI don't think he was actually arguing that K is domain-specific, he was just observing that it seems that way to outsiders. If anything, the most successful applications seem to be with databases (not math), but it's also pretty great for interactive graphics: https://github.com/JohnEarnest/ok/tree/gh-pages/ike https://github.com/JohnEarnest/ok/tree/gh-pages/ike I work at the same company as the author, and we use K3 for all kinds of things -- system administration, network servers, interactive web apps. It's a pretty general purpose language. And you can even do old-school loops if you want. It's just very concise. Also, in K, there's a whole set of one-or-two-character symbols that allow you to express other uses of loops in traditional languages.