9 ms·
Donald Knuth used an Erlang-like notation
- sotojuan 10y agoDoesn't most of this syntax come from Prolog?
- Turing_Machine 10y agoLikely that was its direct source (Erlang was originally developed in Prolog, IIRC). However, the first volume of TAOCP came out in 1968, while Prolog dates from 1972. It's possible that the Prolog team got the notation from Knuth, and then Armstrong, et al carried it forward into Erlang.
- 4ad 10y agoKnuth didn't invent any notation here, it's just standard math. There are a million languages out there that resemble math notation (mostly functional languages), many of them resemble it much better than erlang does.
- gohrt 10y agoClickbait title is clickbait. minimal-syntax languages tend to look similar.
- fusiongyro 10y agoKnuth is simply defining a piecewise function here in ordinary math notation. Functional programming languages borrow heavily from math, Erlang is a functional language. The resemblance would probably be even more striking with Haskell... which only serves to undermine the message. Erlang's great though. Glad to see some irrational exuberance for it.
- old_sound 10y agoWith haskell it will be less similar since Haskell doesn't use the semi-colon to separate function clauses, and the period for delimit the last one. You could argue that Haskell tuples will use the () syntax instead of {} as in Erlang. I've mostly wrote this joke since many Erlang beginners find the semi-colon/period syntax confusing, but then there you have it on an essential book about programming
- sotojuan 10y agoI'm pretty sure many more people find TAOCP confusing than they do Erlang :p
- old_sound 10y agoCan we say: "If you understand the first 20 pages of TAOCP, you understand Erlang"?
- jacquesm 10y agoYou can understand Erlang even if you're not that good at math, but you won't be able to make much of TAOCP if you aren't good at math. One thing is for sure: just trying to read TAOCP will eventually make you better at math.
- old_sound 10y agoThere's no such thing as "being good at math". You either put effort and practice to learn it, or you don't. Fixed va Growth Mindset, etc…
- JadeNB 10y ago> There's no such thing as "being good at math". You either put effort and practice to learn it, or you don't. I agree with your second sentence, and, as a mathematician and a teacher, I think that I agree with the spirit of the first, but I think that it's probably not worded as you mean. Think of the same sentence with, say, 'baseball' in place of 'math': I think that most people would agree with the second sentence, but not the first. By the same token, there's no such thing as "being inherently good" (or, for that matter, inherently bad) "at math"; but I think that it would be silly to pretend that the effort and practice don't make you good (or at least better) at it.
- nayuki 10y agoKnuth's function would be written in Haskell as thus: f [n] = [n] f [m, n] = [m, n, 0, 1] f [m, n, r, 1] = [m, n, mod m n, 2] f [m, n, r, 2] = if r == 0 then [n] else [m, n, r, 3] f [m, n, p, 3] = [n, p, p, 1] It needs to be implemented with variable-length lists instead of fixed-length tuples, in order to satisfy the type system.
- old_sound 10y agoFor me what's striking about Erlang syntax is the meaning of the semi-colon and the period, as function clause separator. Most of the rest is just vanilla FP lang syntax.
- DanielMcLaury 10y agoTo be fair that's just vanilla English orthography.
- old_sound 10y agoYup, and still people get confused at Erlang's use of semi-colons and periods. Do you think it is because other programming languages don't uses the semi-colon that way? Or that periods are usually used to access class members, but not to finish function declarations?
- klibertp 10y agoI think it's because most people have no idea how to use semicolons in natural languages too.
- kbenson 10y agoI think this is true. Anecdotally, I've looked up the usage of semicolons a few times now, and I think I know how to use them, but every time I'm about to I just rephrase what I'm saying so I don't have to. They are used so rarely in English it's hard to feel confident through exposure.
- erez 10y agoI'm waiting for the sequel, Gutenberg used the same characters as in C, making him the first C programmer.
- old_sound 10y agoC predates Gutenberg
- erez 10y agoThat's some deep theosophical kung-fu you bring there, grasshopper. But seeing as the words of the Torah existed before the creation of the world, it might just be that you are correct.
- dllthomas 10y ago"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." - Robert Firth
- krmboya 10y agoHence the 'platonic language ideal' that the author speaks about in the last paragraph?
- paulddraper 10y agoCertainly, though (1) Knuth is mostly irrelevant here and (2) the causality is obfuscated. A more precise title would be "Erlang uses math-like notation (and kudos)"
- deleted 10y ago[deleted]
- pmontra 10y agoTo the eye of a developer used to more modern languages that also shows some bad choices in the design of the Erlang syntax. Basically everything that makes the source code less readable than the original: uppercased variables, the minuses that prefix the module and export statements, the wierd =:= operator. I add the also wierd <> binary and string concatenation operator, not used in this example. The semicolon-period statement separators/terminators are in the original and in natural languages, but newer languages proved them to be useless. Probably compilers in the 80s needed some help by the programmer to be fast. Elixir fixed some of the worst offenders, kept others and added something. Examples: the <> is still there but at least we can interpolate strings Ruby like, the useless do at the end of almost every defsomething declarations (the compiler should get it by itself.) But every languages has its wierdnesses, the contest is to have the least of them.
- sotojuan 10y agoOne thing I don't like about Elixir is the Ruby-style "optional" sytax e.g. `IO.puts "hello"` vs `IO.puts("hello")` and the whole keyword list arguments syntax sugar thing. I mean, I get it now, but it's sorta hard to read as non-Ruby beginner.
- qaq 10y agoHmm you can just use `IO.puts("hello")`
- fzzzy 10y agoThe point is some people don't, making it harder to read that code.
- qaq 10y agoI am afraid the ability of people to write hard to read code is infinite. If you are using Elixir in a production project your team can set a guideline to always use () I have not looked into it but it also likely can be enforced by a linter.
- peterkelly 10y agoIt's called pattern matching, and is present in most functional languages - Haskell is a good example of something which uses this style extensively. In a sense it's derived from the way that some mathematical functions are expressed, e.g. i've seen the fibonacci sequence expressed in this manner a few times. The only thing this excerpt from the book has to do with Erlang is that they both used the same (existing) idea.
- old_sound 10y agoAs mentioned already: >For me what's striking about Erlang syntax is the meaning of the semi-colon and the period, as function clause separator. Most of the rest is just vanilla FP lang syntax. It's strikes me that everybody notices the pattern matching part, but not the way the clauses are separated, which AFAIK, it's something used by Erlang Syntax only. And yeah, after working in Erlang and other FP langs for the past 6 years I kinda know this is called pattern matching ;-)
- avarun 10y agoF# does the same thing I believe.
- klibertp 10y agoWith "verbose syntax" F# (just like OCaml) uses ";" as a generic separator and ";;" for ending top-level definitions. It uses "." for attribute (of modules, objects...) selection.
- kqr 10y ago> it's something used by Erlang Syntax only. Well... and English syntax. In English, you can specify a list of things by separating each thing with a semicolon and then a sentence is terminated by a period. Example: > Today I would like you to buy coffee; talk to Sarah about the party if you can, otherwise send her a text; drop off the kids; meet me at soccer practise. You see how the sentence is terminated with a period, each individual item in the list is separated by a semicolon, and the comma is free to use inside each item to indicate related clauses. I've changed nothing about the structure of that list, except replaced the items with function definitions. > Today I would like you to define f(m, n, r, 1) as f(m, n, remainder of m divided by n, 2); f(m, n, r, 2) as n if r is 0, otherwise as f (m, n, r, 3); f(m, n, p, 3) as f(n, p, p, 1). It's the same thing, only we've replaced the mundane everyday tasks with function definitions. Now reformat the thing and we get Today I would like you to define f(m, n, r, 1) = f(m, n, remainder of m divided by n, 2); f(m, n, r, 2) = n if r is 0, f (m, n, r, 3) otherwise; f(m, n, p, 3) = f(n, p, p, 1). Sure, Erlang syntax happens to coincide with the syntax of English, and I'm not sure whether this was intentional or not, but it certainly has nothing to do with Knuth.
- pwdisswordfish 10y agoThis article reminds me of the "JavaScript is Scheme" meme from a while ago. In that people wanted to increase the prestige of their favourite(?) language by shoehorning it into a comparison with something high-status; which comparison, when you think about it, doesn't make much sense. > Interesting curiosity, which proves that the Erlang Syntax is some sort of Platonic Language Ideal that predates all programming languages. Because it supports definition by cases and an if-then-else construct? And because it uses the same punctuation marks that ordinary natural language sentences do? Give me a break.
- old_sound 10y agoGo get your break, while you are at it, get a laugh or two, because that's what this article is supposed to be about. nobody is so silly to pretend Knuth was describing Erlang on his book.
- rdtsc 10y ago> Because it supports definition by cases and an if-then-else construct? And because it uses the same punctuation marks that ordinary natural language sentences do? Give me a break. Yes, the author, a known Erlang developer and a long time programmer really thought Knuth was using Erlang in this book, and, is now trying to convince you to rewrite every single program you wrote in Erlang as well. Geez...
- unboxed_type 10y agoIts interesting how you squeezed 'Erlang language' into some syntax choices. Erlang is about actor model, not about pattern matching. Joe had his inspiration from Prolog - it is a well-known fact from publicly available sources. Anyway, thanks for the article, it sparked some emotions in my brains :-)
- old_sound 10y agoI know all that. Long time Erlang dev, former RabbitMQ core dev, so yeah, I've heard already about the Prolog story. Interesting you talk about the Actor Model, since even Robert Virding has said that when they created Erlang they had no idea there was a thing called "Actor Model".
- unboxed_type 10y agoWow! Ok. Well yes, as far as I know both Joe and Rob agree on that it is accident that Erlang have implemented 'actor model' thing. Also its interesting to note that functional nature of Erlang is very different to ML-family languages. Authors used all these functional stuff because of pragmatics in the first place and not because of solid theory underpinnings.
- old_sound 10y agoYup. See this convo https://twitter.com/old_sound/status/788349221946662912 https://twitter.com/old_sound/status/788349221946662912
- 4ad 10y agoAuthor confuses standard math notation with erlang, missing the fact that other, more pure, functional programming languages even more closely resemble math notation. Nothing to see here.
- old_sound 10y agoCommenter confuses satire with serious article. Assumes author doesn't know about functional languages. Nothing to see here.
- rdtsc 10y ago> Author confuses standard math notation with erlang, missing the fact that other, The article is silly whimsy, you know that? Knowing the author from online presence, I can assure you the author doesn't really think Knuth was writing Erlang at that time. > that other, more pure, functional programming languages Maybe the author doesn't care about other more pure functional programming languages. They care about Erlang so they wrote about it.
- dang 10y agoThis is a good case of where the HN guidelines call for changing a title of an article: "Please use the original title, unless it is misleading or linkbait." https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html A good HN title is accurate, neutral, and close to the language of the original article. If anyone suggests a better title, we're always happy to change it again.
- old_sound 10y agoIt's not misleading or linkbait. It's just humor. Don't you have humor guidelines at HN?
- dang 10y agoJokes certainly have their place but they're context-dependent, i.e. the same title can work fine in one place but not another.
- old_sound 10y agoIs the website title HackerNews not linkbait or misleading? I ask since I usually don't see many "hacker News" around here…
- dang 10y agoIt's a category error to conflate article titles and website names, but I'll play along. Misleading? Arguably, but I don't think it's much of a stretch from "Hacker News" to "news for hackers" to "anything that good hackers would find interesting", which is the mandate of the site (https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html). Linkbait? I doubt it, but I'm biased.
- mcv 10y agoYou want to rename it to HackerJokes?
- ljbx 10y agoomg, wrong way round. It's more math or logic notation.
- old_sound 10y agoMore like satire logic notation, but who am I to tell at this point.
- totallymike 10y agoHonestly I can't tell sometimes if HN is all just satirical internet comments. I read the article, chuckled at the exchange with Joe Armstrong, then opened the HN comments to look at all the grumbling. Turns out there's plenty.
- pwdisswordfish 10y agoWhat is 'satire logic'? Has it got a different notation from the predicate calculus?
- yellowapple 10y agoAre we sure it ain't just Prolog? In particular, Erlang's syntax is heavily derived from Prolog's, so it's natural to conclude that Prolog would be the closer relative to Knuth's syntax. In reality, though, it's probably the other way around; Prolog's syntax is in turn more-or-less derived from the conventions in traditional math formulas (especially with the uppercase variables and such).
- Xophmeister 10y agoJoe Armstrong's comment on this post is gold just for this: But as Abraham Lincoln said - "don't believe everything you read on the Internet"
- KeytarHero 10y agoUhh, TAOCP predates Erlang by quite a bit. Shouldn't the headline be, "Erlang uses a Donald Knuth-like notation"?
- rdtsc 10y ago> TAOCP predates Erlang by quite a bit. Are you sure Knuth wasn't secretly programming in Erlang since the early 50's. He is considered one of the original inventors, it was just too controversial so it was covered up all this time. I guess we need special whimsy and/or sarcasm tags so people don't take them too seriously...
- GnarfGnarf 10y agoKnuth also created in TeX the notation used by Microsoft's Rich Text Format (RTF): {\b bold} etc.
- rpcope1 10y agoRelated: https://www.youtube.com/watch?v=rRbY3TMUcgQ https://www.youtube.com/watch?v=rRbY3TMUcgQ